Advertisement
TimxAG

10opencup

Oct 1st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include "math.h"
  6. #include <map>
  7. #include "bits/stdc++.h"
  8. using namespace std;
  9. class Tpair {
  10. public:
  11. double t;
  12. double a;
  13. double S;
  14. };
  15. int main() {
  16. int test;
  17. cin >> test;
  18. double v0 = 0;
  19. for (int d = 0; d < test; d++) {
  20. int n, qq;
  21. cin >> n >> qq;double l=qq;
  22. l *= 1000;
  23. map<double, Tpair> a;
  24. for (int i = 0; i < n; i++) {
  25. int as, t;
  26. Tpair b;
  27. cin >> as >> t;
  28. double S = (double)as*t*t/2;
  29. double V = (double)S/t;
  30. b.a = as;b.S = S;b.t = t;
  31. a[V] = b;
  32. }
  33. map<double, Tpair> :: const_iterator it = a.end();
  34. it--;
  35. double ansT = 0;
  36. for (map<double, Tpair> :: const_iterator id = it; id !=a.begin(); id--) {
  37. //v0 += id->first*id->second.a;
  38. double St = (id->second.a)*(pow(id->second.t, 2))/2 + v0*id->second.t;
  39.  
  40. if (St <= l) {
  41. l -= St;
  42. // v0 += id->first * id->second.a;
  43. ansT+=id->second.t;
  44. }
  45. else {
  46. ansT+=sqrt(2*l/id->second.a);
  47. l = 0;
  48. }
  49. v0 += id->second.a * id->second.t; //cout << St << " " << l << " " << v0 << " " << ansT << endl;
  50. }
  51. if (l > 0) {
  52. map<double, Tpair>::const_iterator id = a.begin();
  53. double St = (double) id->second.a * pow(id->second.t, 2) / 2 + (double) v0 * id->second.t;
  54. if (St <= l) {
  55. l -= St;
  56. // v0 += id->first * id->second.a;
  57. ansT+=id->second.t;
  58. } else {
  59. ansT += sqrt(2 * l / id->second.a);
  60. l = 0;
  61. }
  62. v0 += id->second.t * id->second.a; // cout << St << " " << l << " " << v0 << " " << ansT << endl;
  63. }
  64. if (l > 0) {
  65. // cout << endl << l << " " << v0 <<" " << ansT << endl;
  66. ansT += l/v0;
  67. }
  68. //v0 += id->first * id->second.a;
  69. // ansT*=100;ceil(ansT);ansT/=100;
  70. //cout << ceil(ansT*100)/100;
  71. printf("%0.2lf\n", ceil(100*ansT)/100);
  72. // printf("%0.2lf\n", ansT);
  73.  
  74. }
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement