先对序列排个序。

例如: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. 【纯欧拉函数】 poj 2407

    #include <cstdio> #include <iostream> using namespace std; int phi(int x) { int t=x; ;i& ...

  2. OpenGL中glFrustum()和gluPerspective()的相互转换

    OpenGL中在窗口的大小发生变化的时候会触发resize()函数,这里会传入一个新的宽和高,在resize()函数中我们会设置投影矩阵,在可以使用OpenGL基础函数glFrustum()函数和gl ...

  3. Jquery的parent和parents(找到某一特定的祖先元素)

    关于Jquery的parent和parents parent是指取得一个包含着所有匹配元素的唯一父元素的元素集合.parents则是取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素).可以 ...

  4. poll和select

    都允许进程决定是否可以对一个或者多个打开的文件做非阻塞的读取或写入.这些调用也会阻塞进程,直到给定的文件描述符集合中的任何一个可读取或写入.常常用于那些要使用多个输入或输出流而又不会阻塞与其中任意一个 ...

  5. IDL 实现PCA算法

    在多元统计分析中,主成分分析(Principal components analysis,PCA)是一种分析.简化数据集的技术.主成分分析经常用于减少数据集的维数,同时保持数据集中的对方差贡献最大的特 ...

  6. 阅读 LdrInitializeThunk

    参考: http://blog.csdn.net/hw_henry2008/article/details/6568255 Windows 的 DLL 装入(除 ntdll.dll 外)和连接是通过 ...

  7. 激活OFFICE2010时,提示choice.exe不是有效的win32程序

    我在安装office2010破解版时,提示choice.exe不是有效的win32应用程序 删除choice.exe再激活,按提示找到目录删掉这个文件,需要设置显示隐藏文件夹

  8. C++头文件#include<bits/stdc++.h>

    一句话的事,直截了当——#include<bits/stdc++.h>包含C++的所有头文件 参考网站(点击):http://www.tuicool.com/articles/m6neUj ...

  9. jq的合成事件

    jq中有两个合成事件 hover()和toggle() 1.hover() hover方法用于模拟光标悬停事件.当光标移动到元素上时,会触发指定的第一个函数(enter),当光标移出这个元素时,会触发 ...

  10. 转 :Oracle分区表 (Partition Table) 的创建及管理

    三.删除分区 You can drop partitions from range, list, or composite range-list partitioned tables. ALTER T ...