Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <queue>
- using namespace std;
- ifstream cin("muzeu.in");
- ofstream cout("muzeu.out");
- bool v[251][251];
- int min1[251][251];
- int ml[]={1,0,-1,0};
- int mc[]={0,1,0,-1};
- int main()
- {
- int n,i,j,l,c,cntd;
- char ch;
- cin>>n;
- queue<pair<int,int>>deMers;
- queue<int>cnt;
- for(i=1;i<=n;i++){
- for(j=1;j<=n;j++){
- min1[i][j]=9999999;
- cin>>ch;
- if(ch=='#'){
- v[i][j]=1;
- }else if(ch=='P'){
- min1[i][j]=0;
- deMers.push({i,j});
- cnt.push(0);
- }
- }
- }
- while(!deMers.empty()){
- pair<int,int>poz=deMers.front();
- cntd=cnt.front()+1;
- deMers.pop();
- cnt.pop();
- for(j=0;j<4;j++){
- l=poz.first+ml[j];
- c=poz.second+mc[j];
- if(l<=n && c<=n && l>0 && c>0 && v[l][c]!=1 && cntd<min1[l][c]){
- min1[l][c]=cntd;
- cnt.push(cntd);
- deMers.push({l,c});
- }
- }
- }
- for(i=1;i<=n;i++){
- for(j=1;j<n;j++){
- if(v[i][j]==1)
- cout<<"-2 ";
- else if(min1[i][j]==9999999)
- cout<<"-1 " ;
- else
- cout<<" "<<min1[i][j]<<" ";
- }
- if(v[i][j]==1)
- cout<<"-2 ";
- else if(min1[i][j]==9999999)
- cout<<"-1 " ;
- else
- cout<<" "<<min1[i][j];
- cout<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement