华中农业大学第五届程序设计大赛网络同步赛-K

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

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 const int N = 1000005;
 9 int a, book[N], day[N];
10 
11 int main()
12 {
13     int n;
14     while(scanf("%d", &n)!=EOF)
15     {
16         int len = 0;
17         memset(book, 0, sizeof(book));
18         memset(day, 0, sizeof(day));
19         for(int i = 0; i < n; i++)
20         {
21             scanf("%d", &a);
22             if(a <= n)
23               book[a]++;
24             if(a < n && a > len)len = a;
25         }
26         int ans = 1;
27         for(int i = 1; i <= len; i++)
28         {
29             while(book[i]){
30                 bool fg = false;
31                 for(int j = 1; j <= ans; j++){
32                     if(day[j] < i){
33                         book[i]--;
34                         day[j]++;
35                         fg = true;
36                         break;
37                     }
38                 }
39                 if(!fg){
40                     ans++;
41                     day[ans]++;
42                     book[i]--;
43                 }
44             }
45         }
46         printf("%d\n", ans);
47     }
48 
49     return 0;
50 }

 

转载于:https://www.cnblogs.com/Penn000/p/6756251.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值