先对序列排个序。

例如: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. C++ concepts: Compare

    The concept Compare is a set of requirements expected by some of the standard library facilities fro ...

  2. 最简单易懂的webService客户端之soap+xml请求

    代码准备: 1.网络上有提供一些免费的服务器测试地址,可以上这里找一找:https://my.oschina.net/CraneHe/blog/183471 2.我选择了一个翻译地址:http://w ...

  3. Shell特殊变量列表

    特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2. $# 传递给脚本或函数的参数个数. $* 传 ...

  4. jquery 左边分类+插件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. oracle数据库的一次异常起停处理。

    在重启数据库的时候,忘记把一个应用关停了,想起来的时候,就ctrl+c,把数据库shutdown immediate 给强制停下了,把该应用再停止,然后shutdown immdiate,这时候数据报 ...

  6. List、Set、Map集合存放null解析及HashMap、Hashtable异同点解析

    1.List.Set.Map集合存放null解析: @Test public void CollectionTest() { // 测试List List<Object> list = n ...

  7. 本地php 连接 MySQL

    1. 在D:\xampp\htdocs下创建test.php <?php $dbhost = 'localhost:3306'; //mysql服务器主机地址 $dbuser = 'root'; ...

  8. Nape 获取碰撞点加特效

    package { import nape.phys.Body; import nape.shape.Shape; import nape.shape.Circle; import flash.dis ...

  9. 转:Loadrunner打开https报错“Internet…

    Loadrunner 录制htpps 协议通过IE打开页面,报错“Internet Explorer cannot display the webpage”. 但是直接打开IE不通过 loadrunn ...

  10. Dev之ChartControl控件(一)

    ChartControl控件主要包括Chart Title,Legend,Annotations,Diagram,Series五部分:如图: 1.  用RangeControl控件控制ChartCon ...