D. Optimal Number Permutation
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.

Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum .

Input

The only line contains integer n (1 ≤ n ≤ 5·105).

Output

Print 2n integers — the permuted array a that minimizes the value of the sum s.

Examples
input
2
output
1 1 2 2
input
1
output
1 1

题意:使给的上式的值最小,可以发现,最小值可以为0,把简单的几个列一下可以发现规律;

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
if(n%2)
{
for(int i=1;i<=n;i+=2)
printf("%d ",i);
for(int i=n-2;i>0;i-=2)
printf("%d ",i);
for(int i=2;i<n;i+=2)
printf("%d ",i);
for(int i=n-1;i>0;i-=2)
printf("%d ",i);
printf("%d\n",n);
}
else
{
for(int i=1;i<=n;i+=2)
printf("%d ",i);
for(int i=n-1;i>0;i-=2)
printf("%d ",i);
for(int i=2;i<=n;i+=2)
printf("%d ",i);
for(int i=n-2;i>0;i-=2)
printf("%d ",i);
printf("%d\n",n);
}
return 0;
}

最新文章

  1. Bootstrap框架的学习(二)
  2. 微信H5页面内实现一键关注公众号
  3. .gitignore 使用中注意的问题
  4. 委托、IOC全知道
  5. 酷狗 KRC 文件的解析
  6. PLSQL调用webservice
  7. gitlab 启动参考
  8. Hazelcase 简介
  9. redis安装方法
  10. 浅谈CSS布局
  11. for和getElementByTagName配合
  12. echarts 系列一
  13. Oracle 数据库监听无法连接上、监听HANG住、监听无响应、TNS-12560
  14. Django之ContentType组件
  15. node.js 之 N-blog
  16. mssql sqlserver for xml EXPLICIT 用法详解说明
  17. VIP系统
  18. Objective-C block深入理解
  19. 安装ReactNative开发IDE
  20. VS2008 + QGIS1.7.1试验

热门文章

  1. [转]Unity Shader 学习总结
  2. window下python安装pip
  3. LNMP环境搭建(二:MySQL)
  4. 在fc6上搭tftpd
  5. JAVA NIO 简介 (netty源码死磕1.1)
  6. php自定义函数: 加密下载地址
  7. SQL查询 [SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY的区别(比较)] ---转载
  8. go语言之并发编程 channel(1)
  9. GPS基础知识
  10. persisted? vs new_record?