Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- typedef vector<vector<int>> vvi;
- typedef vector<int> vi;
- vvi d;
- vector<string> r;
- vector<string> t; //quien llega primero
- queue<pair<int,int>> q;
- int f,c;
- int df[] = {0,1,0,-1};
- int dc[] = {1,0,-1,0};
- void bfs(int ff, int cc, int ds, char ch){
- if(ff<0 || cc<0) return;
- if(ff>=f || cc>=c) return;
- if(r[ff][cc]=='#') return;
- if(r[ff][cc]=='*') return;
- if(ds>d[ff][cc] && d[ff][cc]!=-1) return;
- //if(d[ff][cc]>0 && d[ff][cc])
- if(r[ff][cc]=='.'){
- r[ff][cc]=ch;
- q.push(make_pair(ff,cc));
- d[ff][cc]=ds;
- }
- else {
- if(ds == d[ff][cc] && ch!=r[ff][cc])
- r[ff][cc]='*';
- }
- }
- int main()
- {
- while(cin>>f){
- cin>>c;
- vvi dist(f, vi (c,-1));
- d = dist;
- vector<string> rr(f, string (c,'7')); //rr es el mapa con los reinos
- r=rr;
- for(int i =0;i<f;++i){
- cin>> r[i];
- for(int dc=0;dc<c;++dc){
- char ch = r[i][dc];
- if(ch >='A' && ch<='Z'){
- q.push(make_pair (i,dc));
- d[i][dc]=0;
- }
- }
- }
- string g; cin>>g;
- while(!q.empty()){
- pair<int,int>
- p=q.front();
- q.pop();
- int ds, ff=p.first, cc=p.second;
- char ch = r[ff][cc];
- ds=d[ff][cc];
- for(int i=0; i<4;++i){
- bfs(ff + df[i], cc + dc[i], ds + 1,ch);
- }
- /*for(auto w: r){ //para ver como se van asignando los caracteres
- cerr<<w<<endl; //es decir, pasito a pasito del BFS
- } cerr<<endl;*/
- }
- for(auto w: r){
- cout<<w<<endl;
- } cout<<"---\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement