minimario

Metro

Feb 15th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <cmath>
  2. #include <algorithm>
  3. #include <iostream>
  4. using namespace std;
  5. int main() {
  6.     int a, b;
  7.     cin >> a >> b;
  8.     bool route[1005][1005];
  9.     double path[1005][1005];
  10.  
  11.     for (int i = 0; i <= 100; i++) {
  12.         for (int j = 0; j <= 100; j++) {
  13.             path[i][j] = 0.0000;
  14.         }
  15.     }
  16.     int q;
  17.     cin >> q;
  18.     for (int i = 0; i < q; i++) {
  19.         int x, y;
  20.         cin >> x >> y;
  21.         route[x][y] = true;
  22.     }
  23.  
  24.     for (int i = 0; i < a+1; i++) {
  25.         for (int j = 0; j < a+1; j++) {
  26.             if (i == 0 && j == 0) {
  27.                 continue;
  28.             }
  29.  
  30.             else if (j == 0) {
  31.                 path[i][j] = path[i-1][j] + 100.00000;
  32.             }
  33.  
  34.             else if (i == 0) {
  35.                 path[i][j] = path[i][j-1] + 100.00000;
  36.             }
  37.  
  38.             else {
  39.                 if (route[i][j]) {
  40.                     path[i][j] = min((double)path[i-1][j]+100.00000, min((double)path[i][j-1]+100.00000, (double)path[i-1][j-1] + 141.42135623730950488016887242097));
  41.                 }
  42.                 else {
  43.                     path[i][j] = min(path[i-1][j]+100.00000, path[i][j-1]+100.00000);
  44.                 }
  45.             }
  46.         }
  47.     }
  48.  
  49.     cout << round(path[a][b]) << endl;
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment