Codeforces Round #491 (Div. 2)---B
程序员文章站
2022-06-02 12:12:18
...
可以改变把一串数字中的某个数变成5,直到平均数四舍五入达到了5
贪心的想法,最先改变最小的数字,平均值上升的越快,所以先排序,挨个修改算平均值,O(nlog(n)) 解决
#include <bits/stdc++.h>
using namespace std;
int a[20000];
int main(){
int n;
cin >> n;
double sum = 0;
for (int i=0; i<n; i++) {
cin >> a[i];
sum += a[i];
}
double ave = sum/n;
ave = floor(ave + 0.5);
sort(a, a+n);
int cnt = 0;
for (int i=0; i<n; i++) {
if (ave == 5) {
break;
}else{
sum = sum - a[i] + 5;
ave = (sum)/n;
ave = floor(ave + 0.5);
cnt++;
}
}
cout << cnt << endl;
}
下一篇: 兼容Firefox浏览器的JS脚本
推荐阅读
-
Codeforces Round #595 (Div. 3)D1D2 贪心 STL
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #656 (Div. 3)D. a-Good String(递归+dfs)
-
Codeforces Round #487 (Div. 2)
-
CodeForces 1324 - Codeforces Round #627 (Div. 3)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #610 (Div. 2)