2016 Winter Training Day #1_D题_codefcrces 432A(贪心)
来源:互联网 发布:ubuntu 16.04 精简下载 编辑:程序博客网 时间:2024/05/16 09:07
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times?
The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, ..., yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
5 20 4 5 1 0
1
6 40 1 2 3 4 5
0
6 50 0 0 0 0 0
2
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits.
题意:每个人可以参加5次ACM ICPC world programming championship(- -不是2次咩),每个队伍要求三人参赛,每个人不得加入两个队伍。给出n和k,n为人数,k为参加比赛的次数。问有多少个队可以完成k次参赛。
思路:简单贪心,将n个人已经参加比赛的次数升序排列,则越靠前的人可以继续参加的比赛越多。(注意是3人组队,所以只需考察第3,,6,9......等下标为3的倍数的人+k后能否 <= 5 就可以了)。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>using namespace std;const int INF = 0x7fffffff;int a[2500];bool cmp(int a, int b){ return a < b;}int main(){ int n, k; cin >> n >> k; for(int i = 0; i < n; ++i) cin >> a[i]; sort(a, a+n, cmp); int ans = 0; for(int i = 2; i < n; i+=3) { if(a[i] + k <= 5) ans++; else break; } cout << ans << endl; return 0;}
- 2016 Winter Training Day #1_D题_codefcrces 432A(贪心)
- 2016 Winter Training Day #1_A题_codefcrces 230A(贪心)
- 2016 Winter Training Day #1_B题_codefcrces 588A(贪心)
- 2016 Winter Training Day #1_E题_codefcrces 514A(贪心)
- 2016 Winter Training Day #1_F题_codefcrces 507A(贪心)
- 2016 Winter Training Day #1_G题_codefcrces 349A(贪心)
- 2016 Winter Training Day #1_C题_hdoj 1009(贪心)
- SZU 2015 Winter Training Day#1
- KTU Programming Camp (Winter Training Day 1)
- SZU 2015 Winter Training Day#2
- SZU 2015 Winter Training Day#3
- SZU 2015 Winter Training Day#4
- SZU 2015 Winter Training Day#5
- SZU 2015 Winter Training Day#6
- Winter Training #1
- 【题解】2016 BUPT Winter Training #2
- UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心
- 【树状数组】2016 BUPT Winter Training #2 D
- cocos2d手游之微信分享sdk的安卓源代码
- bzoj3926诸神眷顾的幻想乡
- 【开源】 天天读报 - 知乎日报win10版
- JavaBean与内省
- Android源码剖析之-------Handler机制详解
- 2016 Winter Training Day #1_D题_codefcrces 432A(贪心)
- 还是优秀的人能够欣赏这个世界的美好
- mxnet 运行自己的数据
- 驱动测试程序编写、驱动程序卸载与测试
- There is already a statement named maxAmountLimit.queryList in this SqlMap
- UI课程(复习之前知识)
- atoi中含有其他字符时是怎么处理的
- Cannot add or update a child row: a foreign key constraint fails
- Android 高德地图2.80新版地图开发详解(本地定位/地图显示/Mark标记/camera移动和缩放)