Birthday

题目大意:(文末原题)

给出n个整数,使两两之间差值尽量小围成一个环,输出这个环;

思路:

将n个数排列,使最大的在中间,往两端减少,就可满足题意;

(也可以直接隔一项输出,再从末尾开始隔一项输出)

代码:

#include <iostream>
#include <algorithm>
using namespace std;int main() {int n;cin >> n;int a[200], ans[200];for(int i = 0; i < n; i++) {cin >> a[i];}sort(a, a + n);int b = 0, e = n - 1;for(int i = 0; i < n; i++) {if(i % 2) ans[e--] = a[i];else ans[b++] = a[i];}for(int i = 0; i < n; i++) {cout << ans[i] << " ";}return 0;
}

原题:

题目:

Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.

Formally, let's number children from 1 to n in a circle order, that is, for every i child with number i will stand next to the child with number i+1, also the child with number 1 stands next to the child with number nn. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.

Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.

输入:

The first line contains a single integer n (2≤n≤100) — the number of the children who came to the cowboy Vlad's birthday.

The second line contains integers a1,a2,…,an (1≤ai≤10^9) denoting heights of every child.

输出:

Print exactly nn integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.

If there are multiple possible answers, print any of them.

样例:

Input:

5
2 1 1 3 2

Output:

1 2 3 2 1

Input:

3
30 10 20

Output:

10 20 30

Codeforce #541(Div.2) C. Birthday (思维、暴力)相关推荐

  1. Codeforces Round #541 (Div. 2)

    Codeforces Round #541 (Div. 2) 题号 题目 知识点 A Sea Battle 思维 B Draw! 贪心模拟 C Birthday 思维 D Gourmet choice ...

  2. L. Ray in the tube(思维暴力)

    L. Ray in the tube(思维&暴力) 思路:思维+暴力. 记:A,BA,BA,B的横坐标距离为xxx. 1.当xxx为奇数时,显然x=1x=1x=1包含所有奇数的情况. 2.当x ...

  3. Codeforces Round #636 (Div. 3) F. Restore the Permutation by Sorted Segments 思维 + 暴力

    传送门 文章目录 题意: 思路: 题意: n≤200n\le200n≤200 思路: 首先关注到rrr从[2,n][2,n][2,n]都出现一次,所以很明显最后一个位置只出现一次,但是这样倒着来不是很 ...

  4. Codeforces Round #619 (Div. 2) E. Nanosoft 思维 + 二维前缀和

    传送门 文章目录 题意: 思路: 题意: 思路: 考虑到最大面积是由四种颜色构成的,且四种颜色可以从中心扩展出去,所以我们分别维护四种颜色的二维前缀和,O(1)O(1)O(1)计算矩阵内颜色的个数.现 ...

  5. Codeforces 846 A Curriculum Vitae 思维 暴力

    题目链接: http://codeforces.com/contest/846/problem/A 题目描述: 给你一个串, 你可以做删除操作, 要求结果串0不能在1的右边, 问最多可以剩几个数字 解 ...

  6. CodeForces - 1168B Good Triple(思维+暴力)

    题目链接:点击查看 题目大意:给出一个长度为n的01字符串,求所有满足条件的区间对数[l,r],使得在区间[l,r]内至少存在一组满足条件的答案,这里第二层的满足条件是指存在两个正整数个x和k,满足s ...

  7. Codeforces Round #323 (Div. 1) B. Once Again... 暴力

    B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...

  8. Codeforces Round #658 (Div. 2) D. Unmerge 思维 + 背包

    传送门 文章目录 题意: 思路: 题意: 思路: 我们可以假设有两个桶,让后向里面放数,可以发现,如果向其中放入了aia_iai​,那么紧跟在他后面的所有<ai<a_i<ai​的数都 ...

  9. Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 暴力 + 补图的遍历

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5. 思路: 这是题是我上个题的一部分,算是个小知识点,暴力能过. 直接维护一个set ...

最新文章

  1. 初学者python编辑器-面向初学者的Python编辑器Mu
  2. java程序练习:猜字母
  3. [APIO2015]巴厘岛的雕塑[按位贪心+dp]
  4. dataframe 如何选中某列的一行_PySpark和SparkSQL基础:如何利用Python编程执行Spark(附代码)
  5. 关于JSP(Java Server Pages)的内置对象有哪些?
  6. 高级政工师具备的能力_北京市高级政工师评审条件
  7. ViBe(Visual Background extractor)背景建模或前景检测
  8. bzoj1211: prufer序列 | [HNOI2004]树的计数
  9. springboot配置请求头大小
  10. swagger连接mysql数据库_一键生成数据库文档,堪称数据库界的Swagger,有点厉害!...
  11. 游戏开发:Html5 虚拟摇杆控制人物移动
  12. nuxt项目添加百度统计的代码
  13. 网站视频链接自动提取下载
  14. 关于椰子汁的学问,你知道多少?
  15. ftp连接服务器失败:响应:220-FileZilla Server version 0.9.24 beta 响应:220-written by Tim Kosse (Tim.Kosse@gmx.d
  16. 暗影精灵8 Pro 安装 Ubuntu20.04 问题记录
  17. 7.4 FIN及其ACK的接收
  18. mac 升级php7.3版本之后Redis扩展升级(phpredis)
  19. Typecho博客评论生成随机用户头像
  20. CNMOOC-os- ch2硬件基础

热门文章

  1. 弗洛伊德算法(Floyd-Warshall)
  2. Wind客户端交易数据读取函数
  3. matlab 求信噪比
  4. python制作报表
  5. 技术人,为什么需要构建知识图谱
  6. function “assert_param“ declared implicitly
  7. html语言换行符,html换行符
  8. matlab如何对三维图进行裁剪,一种三维图像的裁剪方法
  9. 好的提问方式(技术问题)
  10. Arduino与Proteus仿真实例-M24C01串行(I2C)EEPROM数据存取驱动仿真