Problem K: Deadline----思维题

Problem K: Deadline

Time Limit: 2 Sec   Memory Limit: 1280 MB
Submit: 1044   Solved: 100
[ 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

题目链接:http://acm.hzau.edu.cn/problem.php?cid=1029&pid=10


题目的意思就是说程序员每天可以修复一个bug,给你每个bug的最后期限,问你最少需要几个程序员。


我是瞎搞的,同学说n天以后的不用考虑,想了想确实是。

代码:


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e6+7;
int xin[maxn];
int a[maxn];
int cmp(const void *a,const void *b ){
    return *(int *)a-*(int *)b;
}
int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%d",&xin[i]);
        }
        qsort(xin,n,sizeof(xin[0]),cmp);
        int cnt=0;
        for(int i=0;i<n;i++){
            int j=0;
            for(j=0;j<cnt;j++){
                if(xin[i]>a[j]){
                    a[j]++;
                    break;
                }
            }
            if(j>=cnt)
                a[cnt++]=1;
        }
        printf("%d\n",cnt);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值