先对序列排个序。

例如: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. OpenLayer 3 鹰眼控件和全屏显示

    <body> <div id="map"></div> <script> var map=new ol.Map({ target:& ...

  2. Sea Battle

    Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  3. 转:HTML错误编号大全

    HTML错误编号大全 状态行包含HTTP版本.状态代码.与状态代码对应的简短说明信息.在大多数情况下,除了Content-Type之外的所有应答头都是可选的.但Content-Type是必需的,它描述 ...

  4. Fragment里面嵌套Fragment的问题

    最近两天做项目时,要在fragment里面嵌套Fragment,最开始使用Fragment的hide,show等方法一直失败,,如图,message是一个fragment,在里面又有两个子fragme ...

  5. STL笔记之set

    //---------------------------------------------------------// set综述//------------------------------- ...

  6. jq中的移除事件

    unbind([type],[data]); 第一个参数是事件类型,第二个参数是将要移出的函数 说明: 1,如果没有参数,则删除所有绑定的事件 2,如果只提供了事件类型作为参数,则只删除该类型的绑定事 ...

  7. 高性能web开发:如何加载js,,js的存放位置

    外部JS的阻塞下载 所有浏览器在下载JS的时候,会阻止一切其他活动,比如其他资源的下载,内容的呈现等等.至到JS下载.解析.执行完毕后才开始继续并行下载其他资源并呈现内容. 有人会问:为什么JS不能像 ...

  8. 帝国cms文章内容tags关键词设置调用方法以及tags静态化

    说实话帝国cms用起来真的不好找一些功能,就比如说帝国cms的tag标签调用.需要注意的是帝国CMS文章的关键词和tags标签并非一码事,关键词标签是设置文章的关键词的,是用来给搜索引擎说明本篇文章的 ...

  9. discuz 添加板块失败解决办法

    最近把服务器环境升了下级,发现discuz后台添加栏目添加不了了,数据库没变,源代码没变,就突然添加不了了.刚开始添加1个板块成功了,再添加就怎么也添不进去了.只是页面刷新了一下,啥提示没有. 经过一 ...

  10. C#入门经典(1)