Advertisement
K_Y_M_bl_C

Untitled

Dec 18th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. int s, x1, x2, t1, t2, p;
  2. int dir;
  3.  
  4. int solve()
  5. {
  6.     scanf("%d %d %d %d %d %d %d", &s, &x1, &x2, &t1, &t2, &p, &dir);
  7.     int ans = abs(x1 - x2) * t2;
  8.     int rx1 = 0;
  9.     int rx2 = abs(x1 - x2) * t1;
  10.     int ndir = 1;
  11.     if (x1 > x2)
  12.         ndir = -1;
  13.     if (ndir == 1)
  14.     {
  15.         if (dir == 1)
  16.         {
  17.             if (p > x1)
  18.             {
  19.                 rx1 = (s - p) * t1 + s * t1 + x2 * t1;
  20.                 ans = min(rx1, ans);
  21.             }
  22.             else
  23.             {
  24.                 rx1 = (x2 - p) * t1;
  25.                 ans = min(rx1, ans);
  26.             }
  27.         }
  28.         else
  29.         {
  30.             rx1 = p * t1 + x2 * t1;
  31.             ans = min(rx1, ans);
  32.         }
  33.     }
  34.     else
  35.     {
  36.         if (dir == 1)
  37.         {
  38.             rx1 = (s - p) * t1 + (s - x2) * t1;
  39.             ans = min(rx1, ans);
  40.         }
  41.         else
  42.         {
  43.             if (p > x1)
  44.             {
  45.                 rx1 = (p - x2) * t1;
  46.                 ans = min(rx1, ans);
  47.             }
  48.             else
  49.             {
  50.                 rx1 = p * t1 + s * t1 + (s - x2) * t1;
  51.                 ans = min(rx1, ans);
  52.             }
  53.         }
  54.     }
  55.     cout << ans;
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement