SHARE
TWEET

Untitled

a guest Oct 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. typedef long long int ll;
  8. int t, d, n;
  9. vector<int> a, b, p;
  10.  
  11. bool f(double v) {
  12.     int time = 0, len = 0;
  13.     for(int i = 0; i < p.size(); i++) {
  14.         time += (p[i] - len) / v + 1;
  15.         len += p[i];
  16.         if(time % (a[i] + b[i]) <= a[i]) {
  17.             time += (time % (a[i] + b[i])) - 1;
  18.         }
  19.     }
  20.     time += (d - len) / v + 1;
  21.     if(time <= t)
  22.         return true;
  23.     else return false;
  24. }
  25.  
  26.  
  27. int main() {
  28.     //freopen("che.in", "r", stdin);
  29.     //freopen("che.out", "w", stdout);
  30.     cin >> t >> d >> n;
  31.     a.resize(n);
  32.     b.resize(n);
  33.     p.resize(n);
  34.     for(int i = 0; i < n; i++) {
  35.         cin >> a[i] >> b[i] >> p[i];
  36.     }
  37.     double l = 1.0, r = 4;
  38.     for(int i = 0; i < 1000; i++) {
  39.         double m = (r - l) / 2;
  40.         if(f(m)) {
  41.             r = m;
  42.         }
  43.         else l = m;
  44.     }
  45.     cout << l;
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top