Deadline

xiaoxiao2021-02-28  148

题目描述 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


最后期限大于1000000的可以直接忽略,从1到1000000遍历一下所需人数的最大值即可,注意:不能用cin输入,效率太低

#include"iostream" #include"string.h" #include<map> #include"stdio.h" using namespace std; const int max_zhi=1e6; int ai; int ji[max_zhi+20]; int main() { int n; while(cin>>n) { memset(ji,0,sizeof(ji)); int mmax=1; for(int i=0;i<n;i++) { scanf("%d",&ai); if(ai>max_zhi+10) continue; ji[ai]++; } for(int i=1;i<=max_zhi+10;i++) { ji[i]+=ji[i-1]; int cha=(ji[i]*1.0)/i+0.9999; if(cha>mmax) mmax=cha; } cout<<mmax<<endl; } }
转载请注明原文地址: https://www.6miu.com/read-57545.html

最新回复(0)