• A. Almost Equal


    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

    一大一小排列

    1. # include
    2. # include
    3. using namespace std;
    4. int ans[100000*2+10];
    5. int main()
    6. {
    7. int n;
    8. cin>>n;
    9. if(n%2)
    10. {
    11. cout<<"YES"<
    12. int now=1;
    13. for(int i=1;i<=n;i++)
    14. {
    15. if(i%2)
    16. {
    17. ans[i]=now;
    18. ans[i+n]=now+1;
    19. now+=2;
    20. }
    21. else
    22. {
    23. ans[i]=now+1;
    24. ans[i+n]=now;
    25. now+=2;
    26. }
    27. }
    28. for(int i=1;i<=2*n;i++)
    29. {
    30. cout<" ";
    31. }
    32. }
    33. else
    34. {
    35. cout<<"NO"<
    36. }
    37. return 0;
    38. }

  • 相关阅读:
    windows服务器通过nginx配置https
    【SQL Server数据库】视图的使用
    java集合 list转map一些常用的方式(Stream流,,,)
    Java的jstack命令使用详解
    软件设计模式(五):代理模式
    各种构造HTTP请求的方法——最简洁,最易懂~
    揭开 Amazon Bedrock 的神秘面纱 | 基础篇
    IP网络矿用打点紧急广播方案
    qt开发-09_分裂器
    [PHP]empty一直返回true
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126329474