HZAU 1209 Deadline

1209: Deadline

Time Limit: 2 Sec   Memory Limit: 1280 MB
Submit: 1046   Solved: 102
[ Submit][ Status][ Web Board]

Description

     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

       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

       There are one number indicates the answer to the question in a line for each case. 

Sample Input

4 
1 2 3 4

Sample Output

1

HINT

题意:

有n(1<=n<=1000000)个bug需要程序猿来调试,程序员每天可以调试出1个bug,每个bug都必须在xi天前(包括xi)调试出来,求出所需最小程序猿的个数。

思路:

我们首先可以把最后期限xi大于n的不进行统计,因为xi大于n时最多也就只需要1个程序员,那么我们枚举天数1到n一共有多少个bug,bug的数量除于天数可得出到该天时所需要的程序员,如果还有余数那么我们还得再增加一个程序员。

举个例子:

5

1 2 2 3 4

第1天:1/1=1,num=1

第2天:3/2=1......1,num=2

第3天:4/3=1......1,num=2

第4天:5/4=1......1,num=2

第5天:5/5=1,num=1

所需最少的程序员就是2个。

Source

示例程序

#include <cstdio>
#include <cstring>
#include <algorithm>
int a[1000001];			//n最大为1000000,因此数组开到1000000即可
using namespace std;
int main()
{
    int n,i,x,maxx,num,t;
    while(scanf("%d",&n)!=EOF)
    {
        memset(a,0,sizeof(a));
        maxx=1;
        num=0;
        for(i=1;n>=i;i++)
        {
            scanf("%d",&x);
            if(x<=n)
            {
                a[x]++;
            }
        }
        for(i=1;n>=i;i++)
        {
            num=num+a[i];
            t=num/i;
            if(num%i!=0)
            {
                t++;
            }
            maxx=max(maxx,t);
        }
        printf("%d\n",maxx);
    }
    return 0;
}
 
/**************************************************************
    Problem: 1209
    Code Length: 740 B
    Language: C++
    Result: Accepted
    Time:1088 ms
    Memory:4940 kb
****************************************************************/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值