先对序列排个序。

例如: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的更多相关文章

  1. codeforces 258div2 B Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...

  2. codeforces 652B z-sort(思维)

    B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  3. codeforces 652B B. z-sort(水题)

    题目链接: B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)

    题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...

  5. CodeForces 742B Batch Sort

    B. Batch Sort time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. codeforces 340D Bubble Sort Graph(dp,LIS)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has lea ...

  7. 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 ...

  8. 【Codeforces 258B】 Sort the Array

    [题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...

  9. CodeForces 873D Merge Sort 构造 分治

    题意 给出一个归并排序的算法\(mergesort\),如果对于当前区间\([l, r)\)是有序的,则函数直接返回. 否则会分别调用\(mergesort(l, mid)\)和\(mergesort ...

随机推荐

  1. iOS 判断奇偶数

    if (_bigUrlArray.count%2==0) {//如果是偶数 a = i*(_bigUrlArray.count/count);//每个线程图片初始数 b = (i+1)*(_bigUr ...

  2. ngnix配置文件

    使用nginx最大的好处就是负载均衡. #设定负载均衡的服务器列表    upstream service{        server 10.4.29.174:7477;    } server { ...

  3. 分享一款CSS框架

    1.http://bulma.io/documentation/elements 2.支持IE9+ 3.内容:

  4. linux服务器安装php GD扩展库方法

    Strict Standards: Only variables should be assigned by reference in/home/wienholl/public_html/includ ...

  5. redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置

    http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...

  6. 11、组合模式(Composite)

    组合模式有时又叫部分-整体模式在处理类似树形结构的问题时比较方便,看看关系图: 直接来看代码: [java] view plaincopy public class TreeNode { privat ...

  7. ntfs mount fail after upgrade win10

    http://www.cnblogs.com/wangbo2008/p/3782730.html linux下挂载NTFS分区错误修复   今天在linux下打开win的NTFS硬盘总是提示出错了,而 ...

  8. 用C#实现的两个试验编程(txt文本数据的导入,和数据导出为TXT)

    1. 文件的存取 数据文件1.txt为学生成绩统计表,要对它做一个统计工作.文件中若一个人有多个成绩,则取他们的最好成绩来统计,然后计算全班平均成绩:统计0-69.70-79.80-89.90-100 ...

  9. hibernate分页查询的实现

    在mysql中新建数据好USER表,字段有3个,分别是id.username.password,贴上脚本仅供参考     create table `ding`.`user`(         `id ...

  10. python正则表达式例子说明

    pattern = re.compile('<div.*?author">.*?<a.*?<img.*?>(.*?)</a>.*?<div.* ...