CSP-J2020第二题(直播获奖)题解

题目
题目传送门
解题思路
直接桶排序。
参考代码

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	freopen("live.in", "r", stdin);
 	freopen("live.out", "w", stdout);
 	int n, w, a[100000], cnt[601] = {0};
 	cin >> n >> w;
 	for (int i = 0; i < n; i++) {
 		scanf("%d", &a[i]);
 		cnt[a[i]]++;
 		int x = (i + 1) * w / 100;
 		if (!x) x = 1;
 		for (int j = 600, s = 0; j >= 0; j--) {
 			s += cnt[j];
 			if (s >= x) {
 				cout << j << " ";
 				break;
 			}
 		}
 	}
 	return 0;
}

版权声明:本文为yueyuedog原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。