Advertisement
Guest User

Untitled

a guest
May 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. //freopen("test.in" , "r" ,stdin);
  6.  
  7. double a;
  8. double b;
  9. double distance[1024];
  10. double speed[1024];
  11. double max = 100;
  12.  
  13. while(cin >>a , cin >>b){
  14. //cout <<a << " " << b << endl;
  15. double small;
  16. double infinity;
  17. double old;
  18.  
  19.  
  20. for(int i=0;i<a;i++){
  21. cin >> distance[i];
  22. cin >> speed[i];
  23. //cout << "C : " << c[i] << " ";
  24. //cout << "D : " << d[i] << endl;
  25. small = min(old,speed[i]);
  26. old = speed[i];
  27. // cout << "SMALL : " << small << endl;
  28. }
  29.  
  30. small = -small;
  31. infinity = 0x3f3f3f3f;
  32.  
  33. for(int j = 0; j < max; j++) {
  34. double check = (small+infinity)/2;
  35. double sum = 0;
  36. for (int k = 0; k < a && sum < b; k++)
  37. sum += distance[k] / (check + speed[k]);
  38. if (sum > b){
  39. small = check;
  40. }
  41. else{
  42. infinity = check;
  43. }
  44. }
  45. cout << fixed <<setprecision(9) << small << endl;
  46. }
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement