CodeForces 652B z-sort
先对序列排个序。
例如:1 2 3 4 5 6 7
我们把序列分成两半,前一半是1 2 3 4,后一半是5 6 7
然后,我们从前一半取最小的一个,再从后一半取最小的一个。。一直操作下去就能构造出答案了。
由此也可以看到,不可能出现Impossible的情况。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
int n;
int a[maxn];
bool flag[maxn];
int ans[maxn]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a++n);
int st1=,st2=(n+)/+;
int tot=;
while()
{
++tot;
if(tot%==) ans[tot]=a[st1++];
else ans[tot]=a[st2++];
if(tot==n) break;
}
for(int i=;i<=n;i++) printf("%d ",ans[i]);
printf("\n"); return ;
}
CodeForces 652B z-sort的更多相关文章
- codeforces 258div2 B Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...
- codeforces 652B z-sort(思维)
B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- codeforces 652B B. z-sort(水题)
题目链接: B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)
题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...
- CodeForces 742B Batch Sort
B. Batch Sort time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- codeforces 340D Bubble Sort Graph(dp,LIS)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Bubble Sort Graph Iahub recently has lea ...
- Less or Equal CodeForces - 977C (sort+细节)
You are given a sequence of integers of length nn and integer number kk. You should print any intege ...
- 【Codeforces 258B】 Sort the Array
[题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
- CodeForces 873D Merge Sort 构造 分治
题意 给出一个归并排序的算法\(mergesort\),如果对于当前区间\([l, r)\)是有序的,则函数直接返回. 否则会分别调用\(mergesort(l, mid)\)和\(mergesort ...
随机推荐
- OpenLayers 3 的地图基本操作
<body> <div id="map"> <div id="menu"> <button id="zoom ...
- linux跨主机复制文件或文件夹
复制文件基本格式:(本地到远程) scp 文件名 用户名@ip:文件全目录 如果是文件夹加上参数 -r scp -r 基础目录 用户名@ip:目录 栗子: scp local_file remote_ ...
- linux视频学习4(crontab和进程)
1 . crontab定时任务: 任务调度: 系统在某个时间执行的特定的命令. 分类: 1.系统工作.2.个别的用户工作. 设置任务调度文件: /etc/crontab 1.crontab -e : ...
- Java中的值栈
OGNL表示式使用 和 值栈 OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目. Struts2框架使用OGNL作为默认的表达式 ...
- 拖拽加点ui吧
有一段时间没写东西了,真的是静下心来不容易的事情. 把之前的代码再翻看下,想想要加点ui什么的. 2d 塔防ui之前 我看过,但放到3d上做,其实难度是很大的. 不过,这不算什么,关键是 合理的 布 ...
- AI 人工智能 探索 (六)
这次我为 角色 attribute 添加了 多个属性 其中 att 是 好人 坏人 等属性, 显然 数字不同 就要打起来. grade 是智商属性 ,今天先做了 3的智商.也就是小兵智商.碰到就打 逃 ...
- HDU1102--Constructing Roads(最小生成树)
Problem Description There are N villages, which are numbered from 1 to N, and you should build some ...
- IDL 计算TVDI
介绍请看:http://blog.sina.com.cn/s/blog_764b1e9d0100wdrr.html 源码: IDL 源码PRO TVDI,NDVI,LST,NBINS,RES RES ...
- L7,too late
words: parcel,包裹 detective,侦探 expect,期待 airfield,飞机起落的场地 guard,警戒,守卫,n precious,adj,珍贵的 stone,石头 exp ...
- jquery判断节点是否存在
if($('.onloadMore').length>0){ return '节点存在'; }else{ return '节点不存在'; }