fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <cstdio>
  7.  
  8. using namespace std;
  9.  
  10. int n;
  11. double A, e, m, l, r;
  12. vector <double> h;
  13.  
  14. int bin(double m){
  15. h[1] = m;
  16. for (int i = 2; i < n; i++)
  17. {
  18. h[i] = 2 * h[i - 1] + 2 - h[i - 2];
  19. if (h[i] <= 0) return 0;
  20. }
  21. return 1;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. // ios_base::sync_with_stdio(false);
  28. freopen("garland.in", "r", stdin);
  29. freopen("garland.out", "w", stdout);
  30.  
  31. cin >> n >> A;
  32. h.resize(n);
  33. h[0] = A;
  34. l = 0;
  35. r = A;
  36. e = 0.0000001;
  37. while (l + e < r)
  38. {
  39. m = (l + r) / 2;
  40. if (bin(m)){
  41. r = m;
  42. }
  43. else{
  44. l = m;
  45. }
  46. }
  47. printf("%.2f", h[n - 1]);
  48. return 0;
  49. }
Runtime error #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty