码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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. }

  • 相关阅读:
    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
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号