fork download
  1. //Kaori Miyazono, did I reach you ?
  2. //"I can't die because... I have to protect you." -Asuna Yuuki
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. double p, q, r, s, t, u;
  8. double eps = 1e-6;
  9.  
  10. double P(double x){
  11. return p / exp(x) + q * sin(x) + r * cos(x) + s * tan(x) + t * x * x + u;
  12. }
  13.  
  14. int main(){
  15. //ios::sync_with_stdio(0); cin.tie(0);
  16. while(cin >> p >> q >> r >> s >> t >> u){
  17. double l = 0, r = 1;
  18. if (P(l) < 0 && P(r) < 0){
  19. cout << "No solution\n";
  20. }
  21. else if (P(l) > 0 && P(r) > 0){
  22. cout << "No solution\n";
  23. }
  24. else{
  25. while(abs(r - l) > eps){
  26. double mid = (l + r) / 2.0;
  27. if (P(mid) < 0){
  28. r = mid;
  29. }
  30. else{
  31. l = mid;
  32. }
  33. }
  34. printf("%.4f\n", l);
  35. }
  36. }
  37. return 0;
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
Success #stdin #stdout 0s 4516KB
stdin
16 -1 9 -11 -14 18
11 -18 11 -7 -6 16
12 -3 1 -4 -18 19
12 -2 10 -3 -8 1
6 -15 11 -19 -7 -13
9 -7 10 0 -4 -1
15 -1 18 -8 -7 5
20 -6 6 -12 -18 -14
5 -5 3 -10 -15 -1
12 -15 18 -9 -4 -19
stdout
0.9580
0.8911
0.9489
0.9074
0.0976
0.9066
0.9991
0.2879
0.2879
0.2879