Advertisement
aropan

IFMO Training 05. J. Juliani’s Job

Sep 28th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int n, m, ans;
  7. int a[4], k, X1, Y1, X2, Y2;
  8.  
  9. int main()
  10. {
  11.     freopen("job.in", "r", stdin);
  12.     freopen("job.out", "w", stdout);
  13.     scanf("%d %d\n", &n, &m);
  14.     int x = 0;
  15.     char c;
  16.  
  17.     while (scanf("%c", &c) == 1)
  18.     {
  19.         if ('0' <= c && c <= '9')
  20.             x = x * 10 + c - '0';
  21.         else
  22.         {
  23.             if (x)
  24.             {
  25.                 a[k++] = x;
  26.                 x = 0;
  27.             }
  28.         }
  29.     }
  30.  
  31.     X1 = a[0];
  32.     Y1 = a[1];
  33.     X2 = a[2];
  34.     Y2 = a[3];
  35.  
  36.     int dx = X2 - X1;
  37.     int dy = Y2 - Y1;
  38.  
  39.     if (dx && dy)
  40.     {
  41.         int d = min(abs(dx), abs(dy));
  42.         dx /= abs(dx);
  43.         dy /= abs(dy);
  44.         ans = d * 2;
  45.  
  46.         X1 += dx * d;
  47.         Y1 += dy * d;
  48.     }
  49.  
  50.     if (X1 == X2 && Y1 < Y2 && ((X1 + Y1) & 1) == 1) Y1++, ans++;
  51.     if (X1 == X2 && Y2 < Y1 && ((X1 + Y1) & 1) == 1) Y1--, ans++;
  52.     if (Y1 == Y2 && X1 < X2 && ((X1 + Y1) & 1) == 0) X1++, ans++;
  53.     if (Y1 == Y2 && X2 < X1 && ((X1 + Y1) & 1) == 0) X1--, ans++;
  54.  
  55.     ans += abs(X1 - X2) * 2 + (abs(X1 - X2) & 1);
  56.     ans += abs(Y1 - Y2) * 2 + (abs(Y1 - Y2) & 1);
  57.  
  58.     printf("%d\n", ans * 200);
  59.     return 0;
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement