A. Almost Equal
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given integer nn. You have to arrange numbers from 11 to 2n2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:
For every nn consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n2n numbers differ not more than by 11.
For example, choose n=3n=3. On the left you can see an example of a valid arrangement: 1+4+5=101+4+5=10, 4+5+2=114+5+2=11, 5+2+3=105+2+3=10, 2+3+6=112+3+6=11, 3+6+1=103+6+1=10, 6+1+4=116+1+4=11, any two numbers differ by at most 11. On the right you can see an invalid arrangement: for example, 5+1+6=125+1+6=12, and 3+2+4=93+2+4=9, 99 and 1212 differ more than by 11.
Input
The first and the only line contain one integer nn (1≤n≤1051≤n≤105).
Output
If there is no solution, output "NO" in the first line.
If there is a solution, output "YES" in the first line. In the second line output 2n2n numbers — numbers from 11 to 2n2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them.
Examples
input
Copy
3
output
Copy
YES 1 4 5 2 3 6
input
Copy
4
output
Copy
NO
Note
Example from the statement is shown for the first example.
It can be proved that there is no solution in the second example.
=========================================================================
这种规律题目一定是线性推的,也就是从答案1一直推到答案2n。不难发现,1正对着2,3正对着4,5正对着6,并且发现这在坐标上就是+n的位置差别。
且是1 2 4 3 5 6
一大一小排列
- # include
- # include
- using namespace std;
-
- int ans[100000*2+10];
-
- int main()
- {
-
- int n;
-
- cin>>n;
-
- if(n%2)
- {
- cout<<"YES"<
-
- int now=1;
-
- for(int i=1;i<=n;i++)
- {
- if(i%2)
- {
- ans[i]=now;
- ans[i+n]=now+1;
-
- now+=2;
- }
- else
- {
- ans[i]=now+1;
- ans[i+n]=now;
- now+=2;
- }
- }
-
- for(int i=1;i<=2*n;i++)
- {
- cout<
" "; - }
-
-
- }
- else
- {
- cout<<"NO"<
- }
-
-
- return 0;
- }
-
相关阅读:
RK3399驱动开发 | 03 - WK2124串口芯片驱动调试
不可以涩涩!AI续写软件初体验;迁移学习路线图;谷歌新闻非官方搜索API;CS295『因果推理』2021课程资料;前沿论文 | ShowMeAI资讯日报
构建银行人工智能用户画像和自动营销体系
MySQL高阶语句----(二)
javascript(2)高级
目录授予777权限却还是无法进入的解决方案
The 2022 CCPC Guangzhou Onsite M. XOR Sum(数位dp 数位背包)
插入排序(Java实现)
阿里、美团、拼多多、网易大厂面试之Redis+多线程+JVM+微服务...
【C++】引用之带你“消除”C语言版数据结构教材的一些困惑(虽然是C++的内容,但是强烈建议正在学习数据结构的同学点进来看看)
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126329474