Problem K: Deadline
Time Limit: 2 Sec Memory Limit: 1280 MBSubmit: 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;
}