codeforces--652B z-sort(sorting)
来源:互联网 发布:mac如何连接远程服务 编辑:程序博客网 时间:2024/06/09 20:27
传送门
题解
z-sorted sequence 有如下特点:
可以看到,偶数位置上的数总是不小于两边奇数位置上的数,排序后按此规则填即可。
#include <bits/stdc++.h>using namespace std;const int maxn = 1005;int a[maxn], ans[maxn];int main(){ int n; while(cin >> n) { for(int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); int j = -2; for(int i = 0; i <= n / 2 && j < n; ++i) ans[j += 2] = a[i]; //odd j = -1; for(int i = n - 1; i >= n / 2 && j < n; --i) ans[j += 2] = a[i]; //even for(int i = 0; i < n; ++i) cout << ans[i] << " "; cout << endl; } return 0;}
0 0
- codeforces--652B z-sort(sorting)
- Codeforces 652 B. z-sort
- 【Codeforces 652 B z-sort 】
- CodeForces 652B z-sort
- Codeforces 652B z-sort 【思维】
- CodeForces 652B z-sort(构造)
- Codeforces 652B z-sort(水题)
- Codeforces 652B z-sort【水题】
- Educational Codeforces Round 10 B. z-sort
- Educational Codeforces Round 10——B. z-sort
- codeforces 830B. Cards Sorting
- Codeforces B. Cards Sorting 【瞎搞】
- 【Educational Codeforces Round 10B】【简单脑洞】z-sort 数列重排 奇小偶大
- Codeforces 875B Sorting the Coins
- Codeforces 875B Sorting the Coins 题解
- [codeforces]B. Batch Sort 暴力
- codeforces 724B Batch Sort
- codeforces 724B Batch Sort
- 关于大非负整数乘法
- 始终伴随着一种信念
- this是指当前对象自己
- android学习之旅--BaseAdapter细节
- ssh免密码登陆简单原理
- codeforces--652B z-sort(sorting)
- 关闭sublime更新提醒
- Java中的多态性
- ZOJ 1203 Swordfish
- ubuntu12.04设置屏幕开机亮度
- 流量劫持与防范
- sublime 更改字体大小
- redis主从复制
- 联合体(union)的使用方法及其本质