Optimize

 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
#include <stdio.h>
#include <iomanip>
#include <iostream>
#define EPS 1e-9
using namespace std;
int main() {
freopen("optimize.in", "r", stdin);
freopen("optimize.out", "w", stdout);
setprecision(17);
int n;
cin>>n;
double a, b, p, q, r, x[n];
double va,vb,vl,ans=0,l;
for(int i=0; i<n; i++) {
cin>>a>>b>>p>>q>>r;
l=-q/(2.0*p);
va=p*a*a+q*a+r;
vb=p*b*b+q*b+r;
if(a-EPS<l && l<b+EPS) vl=p*l*l+q*l+r;
else vl=999999999;
if(va<vb && va<vl) {
ans+=va;
x[i]=a;
}
else if(vb<=va && vb<vl) {
ans+=vb;
x[i]=b;
}
else {
ans+=vl;
x[i]=l;
}
}
printf("%4.8f\n", ans);
for(int j=0; j<n; j++) {
printf("%4.8f ", x[j]);
}
return 0;
}