codeforces 622D D. Optimal Number Permutation(找规律)
1 second
256 megabytes
standard input
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 .
The only line contains integer n (1 ≤ n ≤ 5·105).
Print 2n integers — the permuted array a that minimizes the value of the sum s.
2
1 1 2 2
1
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(找规律)的更多相关文章
- codeforces 553B B. Kyoya and Permutation(找规律)
题目链接: B. Kyoya and Permutation time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- codeforces Gym 100418D BOPC 打表找规律,求逆元
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- HDU 4279 Number(找规律)
Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- LightOj 1245 --- Harmonic Number (II)找规律
题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题 ...
- hdu 4952 Number Transformation (找规律)
题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...
- Codeforces Round #242 (Div. 2)C(找规律,异或运算)
一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...
- CodeForces 622D Optimal Number Permutation
是一个简单构造题. 请观察公式: 绝对值里面的就是 |di-(n-i)|,即di与(n-i)的差值的绝对值. 事实上,对于任何n,我们都可以构造出来每一个i的di与(n-i)的差值为0. 换句话说,就 ...
随机推荐
- JSP指令用来设置整个JSP页面相关的属性
JSP 指令 JSP指令用来设置整个JSP页面相关的属性,如网页的编码方式和脚本语言. 语法格式如下: <%@ directive attribute="value" %&g ...
- Boost学习总结(一)VS2010环境下编译STLport和Boost
Boost学习总结(一)VS2010环境下编译STLport和Boost Boost简介 Boost库是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库.1998年,Beman G.Da ...
- 解决ubuntu中文乱码问题
方法一: Ubuntu默认的中文字符编码为zh_CN.UTF-8,这个可以在 /etc/environment中看到:sudo gedit /etc/environment可以看到如下内容:PATH= ...
- 调整虚拟机中Linux的分辨率
1 在虚拟机配置中,将显示的缓存提高,CPU也提高. 2 运行Linux,在system-preferences-display中调整分辨率
- pthon 基础 9.8 增加数据
#/usr/bin/python #-*- coding:utf-8 -*- #@Time :2017/11/24 2:59 #@Auther :liuzhenchuan #@File :增加 ...
- Linq实现between拓展
先写一个拓展方法 static class Ext { public static IQueryable<TSource> Between<TSource, TKey> (th ...
- 解决iOS11 UIScrollView下移问题
iOS11 系统为UIScrollView增加一个contentInsetAdjustmentBehavior属性,默认为UIScrollViewContentInsetAdjustmentAutom ...
- Linux c编程:I/O多路复用之select
一般我们在写socet程序的时候调用的accept,recv等操作都是阻塞型的.意思就是如果我们一直收不到数据那么则会被阻塞.所谓阻塞方式block,顾名思义,就是进程或是线程执行到这些函数时必须等待 ...
- maven编译问题-maven项目运行时找不到文件,解决方案之一
问题描述:以上信息是tomcat在启动项目的时候报的错误信息,发现没有找到配置文件,实际上配置文件在项目中是存在的,但是,在编译过程中,配置文件没有能加载到编译后的项目中.就造成了,找不到这些怕配置文 ...
- mysql设置指定ip远程访问连接的方法
本文实例讲述了mysql设置指定ip远程访问连接的方法,分享给大家供大家参考.具体实现方法如下: 1. 授权用户root使用密码jb51从任意主机连接到mysql服务器: 复制代码 代码如下: GRA ...