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;
}

codeforces 622D D. Optimal Number Permutation(找规律)的更多相关文章

  1. codeforces 553B B. Kyoya and Permutation(找规律)

    题目链接: B. Kyoya and Permutation time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  2. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  3. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  4. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  5. HDU 4279 Number(找规律)

    Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. LightOj 1245 --- Harmonic Number (II)找规律

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题 ...

  7. hdu 4952 Number Transformation (找规律)

    题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...

  8. Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...

  9. CodeForces 622D Optimal Number Permutation

    是一个简单构造题. 请观察公式: 绝对值里面的就是 |di-(n-i)|,即di与(n-i)的差值的绝对值. 事实上,对于任何n,我们都可以构造出来每一个i的di与(n-i)的差值为0. 换句话说,就 ...

随机推荐

  1. android Notification 的使用(锁定通知栏)

    近期一直在研究 android .并一边研究一边做应用.当中遇到了把程序通知常驻在 Notification 栏,而且不能被 clear 掉(就像android QQ一样)的问题.经过研究实现了其功能 ...

  2. hdu3293(pell方程+快速幂)

    裸的pell方程. 然后加个快速幂. No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: ...

  3. ArcGIS API for javascript Bookmarks(书签)示例2

    1.运行效果图 说明:这篇博文介绍的书签位于地图之上 有关博文中引用的API文件 怎么iis上部署,请参考我前面的博文 2.HTML代码 <!DOCTYPE html> <html ...

  4. Frobenius inner product

    https://en.wikipedia.org/wiki/Frobenius_inner_product Frobenius norm

  5. What happens when we continue stacking deeper layers on a “plain” convolutional neural network?

    http://cs231n.stanford.edu/slides/2017/cs231n_2017_lecture9.pdf The deeper model performs worse, but ...

  6. css position: relative,absolute具体解释

    关于CSS中 position在布局中非常重要,查了非常多资料都说的非常难理解.以下说说个人的理解: 语法: position: relative | absolute relative: 对象遵循常 ...

  7. Java之线程池(一)

    在前面的文章中,我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统 ...

  8. [Java面试一]Spring总结以及在面试中的一些问题.(转发:http://www.cnblogs.com/wang-meng/p/5701982.html)

    1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ...

  9. LeetCode:救生艇【881】

    LeetCode:救生艇[881] 题目描述 第 i 个人的体重为 people[i],每艘船可以承载的最大重量为 limit. 每艘船最多可同时载两人,但条件是这些人的重量之和最多为 limit. ...

  10. iOS 发大招 otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法 && 编写通用类的时候关于可变参数的处理

    开始 我  以为 这个 alertView 里面 ...的写法  应该 是一个 普通的数组  然 并没有 分享一篇好文 http://www.tekuba.net/program/290/ IOS实现 ...