题目链接:http://codeforces.com/contest/1206/problem/C

题解 : 观察可以发现当n为偶数时,1 - 2n是不满足题意的,可以举例n = 2,n = 4试一试。那么当n为奇数时,则满足题意,通过n = 3和n = 5的情况可以发现一个规律,当a[ 1 ] = 1时候,a[ n + 1] = 2 ,a[ 2 ] =  4,此时 a[ n + 1]  = 3,a[ 3 ] = 5,则a[ n+ 3] = 6,发现a[ i ] 和a[ i + n] 是连续的两个数,而且其奇偶性是交错的,所以猜一下结论:当 i 为奇数时,a[ i ] = 2 * i -1, a[ i + n]  = 2 * i;i为偶数时, a[ i ] =  2 * i , a[ i + n ] = 2 * i - 1 , 模拟一下这个过程即可。

AC代码:

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#define maxn 100005
#define inf 0x3f3f3f3f
using namespace std;
int main(){
int n;
cin>>n;
if(n%2 == 0){
cout<<"NO";
return 0;
}
cout<<"YES"<<endl;
long long int a[n+2];
int cnt = 1;
for(int i = 1;i<=n;i++){
if(i%2 == 0){
cout<<2*i<<" ";
a[cnt] = 2*i-1;
cnt++;
}
else{
cout<<2*i-1<<" ";
a[cnt] = 2*i;
cnt++;
}
}
for(int i = 1;i<=n;i++){
if(i == n){
cout<<a[i];
}
else{
cout<<a[i]<<" ";
}
}
return 0;
}

最新文章

  1. OS.js – 开源的 Web OS 系统,赶快来体验
  2. mysql 创建索引和删除索引
  3. 一周试用yii开发一个带各种该有功能的web程序(二)
  4. [07]APUE:进程环境
  5. 《BI那点儿事》数据流转换——字符映射表
  6. SharePoint 错误集 3
  7. 存储过程优点&amp;缺点
  8. MVC 中DropDownList 用法
  9. Jquery判断滚动条是否到达窗口顶部和底部
  10. android开发之service详解
  11. 转载:C#中事件的由来
  12. HTTP协议初级入门
  13. 主备(keepalived+haproxy)
  14. T-SQL实用查询之查询字段所属的数据库表
  15. pytest学习 一
  16. [随笔][Golang][golang nil 相关]
  17. JS stringObject.Match()
  18. Python安装scrapy过程中出现“Failed building wheel for xxx”
  19. tensorflow如何正确加载预训练词向量
  20. Loadrunner使用键盘快捷键

热门文章

  1. 使用ADO.NET 查询和操作数据
  2. @Configuration@Bean
  3. early-stopping的使用
  4. 《Vue.js实战》--推荐指数⭐⭐⭐⭐
  5. [ C++ ] 常用位运算技巧
  6. Python的特点
  7. 常用UrlEncode编码结果
  8. 虚拟路径引起的bug
  9. 构造和改变一个string的其他方法
  10. 部署prerender服务器