1887: 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
输入描述
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.
输出描述
There are one number indicates the answer to the question in a line for each case.
输入样例
4
1 2 3 4
输出样例
1
分析:
当数大于1e6时可不处理,根据抽屉原理即可得出
以下代码可AC,sort排序了也会超时,也是醉了
附上“超时代码”,避免了上面的情况,依然超时,至今不懂为什么会超时。。。。。。。。。。。。。。真的无语
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int main()
{
int n,num;
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
int sum=0;
int maxi=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&num);
if(num<=n) a[num]++;
}
for(int i=1;i<=n;i++)
{
sum+=a[i];
int cur=sum/i;
if(sum%i!=0) cur++;
maxi=max(maxi,cur);
}
printf("%d\n",maxi);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e6+10;
int a[maxn],b[maxn];
int main()
{
int n;
while(cin>>n)
{
memset(b,0,sizeof(b));
int maxi=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]<maxn) b[a[i]]++;
}
for(int i=1;i<=maxn;i++)
{
b[i]+=b[i-1];
int cur=b[i]/i;
if(b[i]%i!=0) cur++;
maxi=max(maxi,cur);
}
cout<<maxi<<endl;
}
return 0;
}
本文探讨了一道算法题,即在给定多个Bug及其截止日期的情况下,计算至少需要多少名能力相近的工程师才能在截止日期前完成所有Bug的修复工作。文章提供了两种不同的解决方案,一种能够通过评测系统验证正确(AC代码),另一种则因超时未被接受。
930

被折叠的 条评论
为什么被折叠?



