Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5. #define N 20
  6. int t,n,i,j;
  7. struct happy{
  8. double a,b,c;
  9. }h[N];
  10. double f2(double x,double a,double b,double c){return a*(x-b)*(x-b)+c;}
  11. double f(double x){
  12. double ans=0;
  13. for(int i=0;i<n;i++){
  14. ans=max(ans,f2(x,h[i].a,h[i].b,h[i].c));
  15. // cout<<ans<<'\n';
  16. }
  17. return ans;
  18. }
  19. int main(){
  20. cin.tie(NULL);
  21. for(cin>>t;i<t;i++){
  22. for(cin>>n,j=0;j<n;j++)
  23. cin>>h[j].a>>h[j].b>>h[j].c;
  24. double L=0,R=300,M,MM;
  25. while(R-L>1e-7){
  26. M=L+(R-L)/3;
  27. MM=(M+R)/2;
  28. // cout<<L<<' '<<M<<' '<<MM<<' '<<R<<'\n';
  29. if(f(M)>f(MM))L=M;
  30. else R=MM;
  31. }
  32. cout<<fixed<<setprecision(5)<<f(L)<<'\n';
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement