noi2020第二题

原题:https://www.luogu.com.cn/problem/P7072?contestId=37027

满分代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int n,w,num,t[605];
 4 int ans;
 5 int main(){
 6     cin>>n>>w;
 7     for(int i=1;i<=n;i++){
 8         cin>>num;
 9         t[num]++;//当前编号的桶数量加一
10         int m=floor(i*w/100);
11         int sum=max(1,m);
12         for(int j=600;j>=0;j--){//由于分数是600封顶,所以只需要枚举600个编号,于是时间复杂度为n*600,最多60000000=6*10^7,不会超时
13             ans+=t[j];
14             if(ans>=sum){
15                 cout<<j<<" ";
16                 ans=0;
17                 break;
18             }
19         } 
20     }
21     return 0;
22 }

本题我们采用桶排序,什么时候桶的数量不小于获奖人数,什么时候停止,并且输出当前枚举桶的编号

posted @ 2020-11-21 22:09  九州霜  阅读(117)  评论(0编辑  收藏  举报