mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-10 06:38:48 +00:00
P1883 函数
R43928510
This commit is contained in:
parent
6c0ef55d37
commit
344cf78d04
40
problem/P1883/P1883.cpp
Normal file
40
problem/P1883/P1883.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int t, n, a[10005], b[10005], c[10005];
|
||||
|
||||
double f(double x, int i) {
|
||||
return x * x * a[i] + x * b[i] + c[i];
|
||||
}
|
||||
|
||||
double check(double x) {
|
||||
double ans = f(x, 1);
|
||||
for (int i = 2; i <= n; i++) {
|
||||
ans = max(ans, f(x, i));
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i] >> b[i] >> c[i];
|
||||
}
|
||||
double l = 0.00, r = 1000.00, mid1, mid2;
|
||||
while (r - l > 1e-11) {
|
||||
mid1 = l + (r - l) / 3.0;
|
||||
mid2 = r - (r - l) / 3.0;
|
||||
if (check(mid1) > check(mid2)) {
|
||||
l = mid1;
|
||||
}
|
||||
else {
|
||||
r = mid2;
|
||||
}
|
||||
}
|
||||
cout << fixed << setprecision(4) << check(l) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user