mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
C - 二八定律
This commit is contained in:
parent
c120cb7353
commit
6062573cd5
43
XJOI/contest/22a/C/C.cpp
Normal file
43
XJOI/contest/22a/C/C.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n, a[N], sum[N];
|
||||
double ans_a, ans_b;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
std::sort(a + 1, a + 1 + n, std::greater<int>());
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
sum[i] = sum[i - 1] + a[i];
|
||||
}
|
||||
|
||||
ans_a = 100.0 * 1 / n;
|
||||
ans_b = 1.0 * sum[1] * 100 / sum[n];
|
||||
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (1.0 * sum[i] * 100 / sum[n] - 100.0 * i / n >= ans_b - ans_a) {
|
||||
ans_a = 100.0 * i / n;
|
||||
ans_b = 1.0 * sum[i] * 100 / sum[n];
|
||||
}
|
||||
}
|
||||
|
||||
cout << std::fixed << std::setprecision(2) << ans_a << ' '
|
||||
<< std::fixed << std::setprecision(2) << ans_b << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user