Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <fstream>
- #include <queue>
- using namespace std;
- ifstream fin ("palat.in");
- ofstream fout ("palat.out");
- struct poz
- {
- int x,y;
- };
- poz f[1000000];
- int a[1001][1001],n,m,i,j,k,mini=100000000,ix,jx;
- int dx[]= {0,1,0,-1};
- int dy[]= {-1,0,1,0};
- char x;
- queue<poz>q;
- int main()
- {
- fin>>n>>m;
- k=0;
- for(i=1; i<=n; i++)
- for(j=1; j<=m; j++)
- {
- fin>>x;
- if(x=='Z')
- a[i][j]=-1;
- else if(x=='I')
- {
- a[i][j]=1;
- q.push({i,j});
- }
- else if(x=='F')
- {
- k++;
- f[k]= {i,j};
- }
- }
- for(i=0; i<=n+1; i++)
- a[i][0]=a[i][m+1]=-1;
- for(j=0; j<=m+1; j++)
- a[0][j]=a[n+1][j]=-1;
- poz p1,p2;
- while(!q.empty())
- {
- p1=q.front();
- q.pop();
- for(i=0; i<4; i++)
- {
- p2.x=p1.x+dx[i];
- p2.y=p1.y+dy[i];
- if(a[p2.x][p2.y]==0)
- {
- a[p2.x][p2.y]=a[p1.x][p1.y]+1;
- q.push(p2);
- }
- }
- }
- for(i=k;i>=1;i--)
- {
- if(a[f[k].x][f[k].y]<mini)
- mini=a[f[k].x][f[k].y],ix=f[k].x,jx=f[k].y;
- }
- fout<<ix<<' '<<jx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement