Advertisement
Manioc

fuga das galinhas

Aug 6th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int _x[4] = {0, 1, 0, -1};
  6. int _y[4] = {1, 0, -1, 0};
  7. int n, m, end_x, end_y, begin_x, begin_y;
  8. bool check(int x, int y){
  9.     return x <= n && x > 0 && y <= m && y > 0;
  10. }
  11.  
  12. int vis[17][17],val[17][17], ans;
  13. void complete(int l, int c, int qnt){
  14.     vis[l][c] = true;
  15.     //val[l][c] = max(val[l][c], qnt);
  16.  
  17.     if(l == end_x && c == end_y) ans = max(ans, qnt);
  18.     for(int i = 0; i < 4; i++){
  19.         int x = l + _x[i];
  20.         int y = c + _y[i];
  21.         if(check(x, y) && !vis[x][y]){
  22.             complete(x, y, qnt + 1);
  23.         }
  24.     }
  25.  
  26.     vis[l][c] = false;
  27. }
  28. int main(){
  29.     scanf("%d %d", &n, &m);
  30.     n = (n+1)/2;
  31.     m = (m+1)/2;
  32.     scanf("%d %d", &begin_x, &begin_y);
  33.     begin_x = (begin_x + 1)/2;
  34.     begin_y = (begin_y + 1)/2;
  35.     scanf("%d %d", &end_x, &end_y);
  36.     end_x = (end_x + 1)/2;
  37.     end_y = (end_y + 1)/2;
  38.  
  39.     ans = 0;
  40.     complete(begin_x, begin_y, 0);
  41.     //for(int i = 1; i <= n; i++){
  42.     //    for(int j = 1; j <= m; j++) cout << val[i][j] << " \n"[j == m];
  43.     //}
  44.     printf("%d", 2*ans + 1);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement