Codeforces Round #541 (Div. 2) C.Birthday
链接:https://codeforces.com/contest/1131/problem/C
题意:
求给的n个数,相邻差值最小的排列方式。1-n相邻。
思路:
sort后隔一个取一个,取到底后再反着取剩下的。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 100 + 10;
int a[MAXN]; int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
sort(a + 1, a + 1 + n);
vector<int> res;
vector<int> tmp;
for (int i = 1;i <= n;i += 2)
res.push_back(a[i]);
for (int i = 2;i <= n;i += 2)
tmp.push_back(a[i]);
reverse(tmp.begin(), tmp.end());
for (auto x : tmp)
res.push_back(x);
for (auto x : res)
cout << x << ' '; return 0;
}
Codeforces Round #541 (Div. 2) C.Birthday的更多相关文章
- Codeforces Round #541 (Div. 2)
Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...
- Codeforces Round #541 (Div. 2)题解
不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序
https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...
- Codeforces Round #541 (Div. 2) B.Draw!
链接:https://codeforces.com/contest/1131/problem/B 题意: 给n次足球比分,求存在平局的机会. 思路: 结构体存储,unique后,判断是否有分数交叉. ...
- Codeforces Round #541 (Div. 2) A.Sea Battle
链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
随机推荐
- linux vsftpd
FTP是CS架构的.使用的是ftp协议. root@ubuntu:/# apt install vsftpd root@ubuntu:/# service vsftpd status ● vsftpd ...
- 在windows下把Mongodb设置系统服务
把Mongodb Server 设置为系统,方便启动与停止 今天一时兴起在本地安装了下Mongodb服务,安装完后,创建了配置文件为数据库服务指明在哪里存储数据库原始文件,随即就启动了mongo se ...
- leetcode 748. Shortest Completing Word
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
- 负载均衡LVS
可参考:http://ixdba.blog.51cto.com/2895551/555738 http://os.51cto.com/art/201202/319979.html 也可以参考官网:ht ...
- android中样式和自定义button样式
1)自定义button样式 一.采用图片方式 首先新建Android XML文件,类型选Drawable,根结点选selector,自定义一个文件名. 随后,开发环境自动在新建的文件里加了select ...
- UVA10689 Yet another Number Sequence —— 斐波那契、矩阵快速幂
题目链接:https://vjudge.net/problem/UVA-10689 题解: 代码如下: #include <iostream> #include <cstdio> ...
- 【CQ18高一暑假前挑战赛1】标程
[A] #include<bits/stdc++.h> using namespace std; #define ll long long ll qpow(ll a,ll x,ll Mod ...
- groovy语言和grails框架
Groovy 是一种动态语言,它在 JVM 上运行,并且与 Java 语言无缝集成. Groovy 可以大大减少 Java 代码的数量.在 Groovy 中,不再需要为字段编写 getter 和 se ...
- bzoj 4559 [JLoi2016]成绩比较 —— DP+拉格朗日插值
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4559 看了看拉格朗日插值:http://www.cnblogs.com/ECJTUACM-8 ...
- wx:for wx:for-items wx:for-item
data:{ arr:[1,2,3,4,5], arrs:[[1,2,3,4,5],[1,2,3,4,5]] }wx:for 用于循环数组 默认数组的当前项的下标变量名默认为 index,数组当 ...