-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path12097.cpp
69 lines (58 loc) · 1.24 KB
/
12097.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
miscellaneous > binary search > on answer
difficulty: medium
date: 29/Dec/2019
by: @brpapa
*/
#include <cmath>
#include <iostream>
#include <vector>
#define EPS 1e-5
using namespace std;
vector<double> piesVol;
// 1 barriga só pode comer 1 pedaço de 1 torta
bool can(double v, int B) {
// v: volume do pedaço
// B: qte de barrigas famintas
int b = 0;
for (double pieVol : piesVol) {
double leftPieVol = pieVol;
while (leftPieVol - v >= 0) {
leftPieVol -= v;
b++;
}
if (b >= B)
return true;
}
return false;
}
int main() {
int T;
cin >> T;
while (T--) {
int N, B;
cin >> N >> B;
B++;
piesVol.assign(N, 0);
int radii;
double sumPiesVol = 0;
for (double &pieVol : piesVol) {
cin >> radii;
pieVol = M_PI * radii * radii;
sumPiesVol += pieVol;
}
double low = 0, high = sumPiesVol / B;
double ans = 0; // volume do pedaço
while (high - low > EPS) {
double mid = (low + high) / 2;
if (can(mid, B)) {
ans = mid;
low = mid;
} else {
high = mid;
}
}
printf("%.4lf\n", ans);
}
return 0;
}