Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string.h>
- #include <algorithm>
- #include "math.h"
- #include <map>
- #include "bits/stdc++.h"
- using namespace std;
- class Tpair {
- public:
- double t;
- double a;
- double S;
- };
- int main() {
- int test;
- cin >> test;
- double v0 = 0;
- for (int d = 0; d < test; d++) {
- int n, qq;
- cin >> n >> qq;double l=qq;
- l *= 1000;
- map<double, Tpair> a;
- for (int i = 0; i < n; i++) {
- int as, t;
- Tpair b;
- cin >> as >> t;
- double S = (double)as*t*t/2;
- double V = (double)S/t;
- b.a = as;b.S = S;b.t = t;
- a[V] = b;
- }
- map<double, Tpair> :: const_iterator it = a.end();
- it--;
- double ansT = 0;
- for (map<double, Tpair> :: const_iterator id = it; id !=a.begin(); id--) {
- //v0 += id->first*id->second.a;
- double St = (id->second.a)*(pow(id->second.t, 2))/2 + v0*id->second.t;
- if (St <= l) {
- l -= St;
- // v0 += id->first * id->second.a;
- ansT+=id->second.t;
- }
- else {
- ansT+=sqrt(2*l/id->second.a);
- l = 0;
- }
- v0 += id->second.a * id->second.t; //cout << St << " " << l << " " << v0 << " " << ansT << endl;
- }
- if (l > 0) {
- map<double, Tpair>::const_iterator id = a.begin();
- double St = (double) id->second.a * pow(id->second.t, 2) / 2 + (double) v0 * id->second.t;
- if (St <= l) {
- l -= St;
- // v0 += id->first * id->second.a;
- ansT+=id->second.t;
- } else {
- ansT += sqrt(2 * l / id->second.a);
- l = 0;
- }
- v0 += id->second.t * id->second.a; // cout << St << " " << l << " " << v0 << " " << ansT << endl;
- }
- if (l > 0) {
- // cout << endl << l << " " << v0 <<" " << ansT << endl;
- ansT += l/v0;
- }
- //v0 += id->first * id->second.a;
- // ansT*=100;ceil(ansT);ansT/=100;
- //cout << ceil(ansT*100)/100;
- printf("%0.2lf\n", ceil(100*ansT)/100);
- // printf("%0.2lf\n", ansT);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement