codeforces 622D D. Optimal Number Permutation(找规律)
2024-08-29 12:09:04
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;
}
最新文章
- Bootstrap框架的学习(二)
- 微信H5页面内实现一键关注公众号
- .gitignore 使用中注意的问题
- 委托、IOC全知道
- 酷狗 KRC 文件的解析
- PLSQL调用webservice
- gitlab 启动参考
- Hazelcase 简介
- redis安装方法
- 浅谈CSS布局
- for和getElementByTagName配合
- echarts 系列一
- Oracle 数据库监听无法连接上、监听HANG住、监听无响应、TNS-12560
- Django之ContentType组件
- node.js 之 N-blog
- mssql sqlserver for xml EXPLICIT 用法详解说明
- VIP系统
- Objective-C block深入理解
- 安装ReactNative开发IDE
- VS2008 + QGIS1.7.1试验
热门文章
- [转]Unity Shader 学习总结
- window下python安装pip
- LNMP环境搭建(二:MySQL)
- 在fc6上搭tftpd
- JAVA NIO 简介 (netty源码死磕1.1)
- php自定义函数: 加密下载地址
- SQL查询 [SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY的区别(比较)] ---转载
- go语言之并发编程 channel(1)
- GPS基础知识
- persisted? vs new_record?