Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("gigelajungeacasa.in");
- ofstream g("gigelajungeacasa.out");
- int v[1002][1002];
- struct Punct{
- int i,j;
- };
- void rezdrum(int x,int y){
- int i=x;
- int j=y;
- v[x][y]=1;
- queue<Punct> c;
- c.push({i,j});
- while(!c.empty()){
- if(v[i-1][j]==0){
- v[i-1][j]=v[i][j]+1;
- c.push({i-1,j});
- }
- if(v[i][j+1]==0){
- v[i][j+1]=v[i][j]+1;
- c.push({i,j+1});
- }
- if(v[i+1][j]==0){
- v[i+1][j]=v[i][j]+1;
- c.push({i+1,j});
- }
- if(v[i][j-1]==0){
- v[i][j-1]=v[i][j]+1;
- c.push({i,j-1});
- }
- if(v[i-1][j+1]==0){
- v[i-1][j+1]=v[i][j]+1;
- c.push({i-1,j+1});
- }
- if(v[i+1][j-1]==0){
- v[i+1][j-1]=v[i][j]+1;
- c.push({i+1,j-1});
- }
- if(v[i+1][j+1]==0){
- v[i+1][j+1]=v[i][j]+1;
- c.push({i+1,j+1});
- }
- if(v[i-1][j-1]==0){
- v[i-1][j-1]=v[i][j]+1;
- c.push({i-1,j-1});
- }
- c.pop();
- i=c.front().i;
- j=c.front().j;
- }
- }
- int main()
- {
- int n,m,k,X1,Y1,x2,y2,x,y,xy,yy,xb,yb;
- f>>n>>m>>k;
- f>>X1>>Y1>>x2>>y2;
- f>>xy>>yy>>xb>>yb;
- for(int i=1;i<=k;++i){
- f>>x>>y;
- v[x][y]=-1;
- }
- v[X1][Y1]=0;
- v[x2][y2]=1;
- v[xy][yy]=v[xb][yb]=-1;
- for(int i=0;i<=n+1;i++)
- v[i][0]=v[i][m+1]=-1;
- for(int j=0;j<=m+1;++j)
- v[0][j]=v[n+1][j]=-1;
- rezdrum(x2,y2);
- g<<v[X1][Y1]-1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement