Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("gigelajungeacasa.in");
  4. ofstream g("gigelajungeacasa.out");
  5.  
  6. int v[1002][1002];
  7.  
  8. struct Punct{
  9.    int i,j;
  10. };
  11.  
  12. void rezdrum(int x,int y){
  13.     int i=x;
  14.     int j=y;
  15.     v[x][y]=1;
  16.     queue<Punct> c;
  17.     c.push({i,j});
  18.     while(!c.empty()){
  19.         if(v[i-1][j]==0){
  20.             v[i-1][j]=v[i][j]+1;
  21.             c.push({i-1,j});
  22.         }
  23.         if(v[i][j+1]==0){
  24.             v[i][j+1]=v[i][j]+1;
  25.             c.push({i,j+1});
  26.         }
  27.         if(v[i+1][j]==0){
  28.             v[i+1][j]=v[i][j]+1;
  29.             c.push({i+1,j});
  30.         }
  31.         if(v[i][j-1]==0){
  32.             v[i][j-1]=v[i][j]+1;
  33.             c.push({i,j-1});
  34.         }
  35.         if(v[i-1][j+1]==0){
  36.             v[i-1][j+1]=v[i][j]+1;
  37.             c.push({i-1,j+1});
  38.         }
  39.         if(v[i+1][j-1]==0){
  40.             v[i+1][j-1]=v[i][j]+1;
  41.             c.push({i+1,j-1});
  42.         }
  43.         if(v[i+1][j+1]==0){
  44.             v[i+1][j+1]=v[i][j]+1;
  45.             c.push({i+1,j+1});
  46.         }
  47.         if(v[i-1][j-1]==0){
  48.             v[i-1][j-1]=v[i][j]+1;
  49.             c.push({i-1,j-1});
  50.         }
  51.         c.pop();
  52.         i=c.front().i;
  53.         j=c.front().j;
  54.     }
  55. }
  56.  
  57. int main()
  58. {
  59.     int n,m,k,X1,Y1,x2,y2,x,y,xy,yy,xb,yb;
  60.     f>>n>>m>>k;
  61.     f>>X1>>Y1>>x2>>y2;
  62.     f>>xy>>yy>>xb>>yb;
  63.     for(int i=1;i<=k;++i){
  64.         f>>x>>y;
  65.         v[x][y]=-1;
  66.     }
  67.     v[X1][Y1]=0;
  68.     v[x2][y2]=1;
  69.     v[xy][yy]=v[xb][yb]=-1;
  70.     for(int i=0;i<=n+1;i++)
  71.         v[i][0]=v[i][m+1]=-1;
  72.     for(int j=0;j<=m+1;++j)
  73.         v[0][j]=v[n+1][j]=-1;
  74.     rezdrum(x2,y2);
  75.     g<<v[X1][Y1]-1;
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement