Codeforces Round #544 (Div. 3) C. Balanced Team
链接:https://codeforces.com/contest/1133/problem/C
题意:
给n个数, 在这n个数中选最多n个数,来组成一个队伍。
保证这n个数的最大最小差值不大于5。
求最多能选几个数。
思路:
排序,二分,对每个数从后往前找比他差5的第一个数。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 2e5 + 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);
int res = 0;
for (int i = 1;i <= n;i++)
{
int w = upper_bound(a + 1, a + 1 + n, a[i] + 5) - a;
res = max(res, w - i);
}
cout << res << endl; return 0;
}
Codeforces Round #544 (Div. 3) C. Balanced Team的更多相关文章
- Codeforces Round #544 (Div. 3) 题解
Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization 题目链接:https://codeforces.com/contest/113 ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- Codeforces Round #544 (Div. 3) Editorial C. Balanced Team
http://codeforces.com/contest/1133/problem/Ctime limit per test 2 secondsmemory limit per test 256 m ...
- CodeForces Round #544 Div.3
A. Middle of the Contest 代码: #include <bits/stdc++.h> using namespace std; int h1, m1, h2, m2; ...
- Codeforces Round #544 (Div. 3)解题报告
A.Middle of the Contest 考虑把输入的时间单位化成分钟,相加除以2就好了 #include<bits/stdc++.h> using namespace std; # ...
- Codeforces Round #544 (Div. 3) E. K Balanced Teams (DP)
题意:有\(n\)个人,每个人的能力值是\(a_i\),现在你想将这些人分成\(k\)组(没必要全选),但是每组中最高水平和最低水平的人的能力差值必须\(\le 5\),问最多能选多少人. 题解:想了 ...
- Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins
http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch
http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...
随机推荐
- 杭电 1596 find the safest road (最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...
- 每天一个JavaScript实例-apply和call的使用方法
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Mahout 0.5部署
Mahout下载与安装 1.下载Mahout.到地址[1]可以找到镜像地址.我们下载Mahout 0.5.请将mahout-distribution-0.5.tar.gz和mahout-distrib ...
- ICMP协议 广播以查询局域网内的所有主机
看到了很多局域网内的主机扫描工具,在想怎么去实现这样一个工具.前几天看了Ping源码--ICMP协议的实例,ICMP可以用来探测网联网内的任一主机,ICMP和广播地址结合来扫描局域网内的所有主机不是很 ...
- linux杀死进程
http://blog.csdn.net/andy572633/article/details/7211546 ps -ef | grep firefox kill -s 9 1827
- spring的依赖注入(DI)、控制反转(IOC)和面向切面(AOP)
在spring的配置文件增加 <context:component-scan base-package="com.jmu.ccjoin.service"/> <c ...
- ref 与 $refs 如何关联
先问大家一个简单的问题: 还有人记得 jquery 里面的 data 方法是如何让 DOM 节点绑定对应的数据对象的吗 有时候我们做节点关联设计的思路其实有一点类似,但是在 vue 里面多了很多概念, ...
- HDU2181 哈密顿绕行世界问题 —— DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- BM算法模式匹配——字符串与KMP比较
下面是代码:BM是什么参考阮一峰老师的讲解 点击打开链接 #include<iostream> #include<algorithm> #include<string. ...
- bzoj3653
主席树+dfs序 b在a上方时可以O(1)算出来,子树中就用主席树查询区间和,权值线段树的下标是深度,值是子树size-1,每次查询就行了...线段树合并挂了 #include<bits/std ...