华中农业大学第五届程序设计大赛网络同步赛-K
2017-04-24 12:26
316 查看
K.Deadline
There are N bugs to be repaired and some engineers whose abilities are roughly equal. And an engineer can repair a bug per day. Each bug has a deadline A[i].
Question: How many engineers can repair all bugs before those deadlines at least? 1<=n<= 1e6. 1<=a[i] <=1e9
Input
Description There are multiply test cases. In each case, the first line is an integer N , indicates the number of bugs. The next line is n integers indicates the deadlines of those bugs.
Output
Description There are one number indicates the answer to the question in a line for each case.
Input
4 1 2 3 4
Output
1
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 1000005; int a, book , day ; int main() { int n; while(scanf("%d", &n)!=EOF) { int len = 0; memset(book, 0, sizeof(book)); memset(day, 0, sizeof(day)); for(int i = 0; i < n; i++) { scanf("%d", &a); if(a <= n) book[a]++; if(a < n && a > len)len = a; } int ans = 1; for(int i = 1; i <= len; i++) { while(book[i]){ bool fg = false; for(int j = 1; j <= ans; j++){ if(day[j] < i){ book[i]--; day[j]++; fg = true; break; } } if(!fg){ ans++; day[ans]++; book[i]--; } } } printf("%d\n", ans); } return 0; }
相关文章推荐
- 华中农业大学第五届程序设计大赛网络同步赛 H MathematicalGame
- 华中农业大学第五届程序设计大赛网络同步赛 C Friends
- 华中农业大学第五届程序设计大赛网络同步赛-L
- 华中农业大学第五届程序设计大赛网络同步赛-D
- 华中农业大学第五届程序设计大赛网络同步赛解题报告2(转)
- 华中农业大学第五届程序设计大赛网络同步赛解题报告(转)
- 华中农业大学第五届程序设计大赛网络同步赛-A
- 有一种绝望叫做无限PE hzau 1207 Candies (华中农业大学第五届程序设计大赛网络同步赛 I题)
- 华中农业大学第五届程序设计大赛网络同步赛
- 华中农业大学第五届程序设计大赛网络同步赛题解
- 华中农业大学第五届程序设计大赛网络同步赛-G
- [HZAU]华中农业大学第四届程序设计大赛网络同步赛
- 华中农业大学第四届程序设计大赛网络同步赛 Arithmetic Sequence
- 华中农业大学第四届程序设计大赛网络同步赛 J
- 华中农业大学第四届程序设计大赛网络同步赛 D题 Robbing Red Packets
- Problem J: Arithmetic Sequence——华中农业大学第四届程序设计大赛网络同步赛题目
- 华中农业大学第四届程序设计大赛网络同步赛解题报告
- 华中农业大学第四届程序设计大赛网络同步赛Problem I: Catching Dogs
- Contest1009 - 华中农业大学第四届程序设计大赛网络同步赛C,H,J
- 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列