Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define rep(i,j,n) for(int i = int(j); i < int(n); ++i)
- struct pi{
- int f, c;
- pi(int a, int b): f(a), c(b){}
- pi(){}
- };
- int n, m, d;
- pi ch, xx;
- vector<vector<char>> v;
- vector<vector<int>> g;
- vector<bool> vis;
- int mf[8] = {-1, 0, 1, 0, 1, -1, 1, -1},
- mc[8] = { 0, 1, 0, -1, 1, -1, -1, 1};
- int ind(const pi& p){ return p.f*m + p.c;}
- pi fpi(const int& i){ return pi(i/m, i%m);}
- void dfs(){
- stack<int> s;
- int idx = ind(ch);
- s.push(idx);
- vis[idx] = true;
- while(!s.empty()){
- int vtx = s.top();
- s.pop();
- rep(i, 0, g[vtx].size()){
- int nei = g[vtx][i];
- if(!vis[nei]){
- vis[nei] = true;
- s.push(nei);
- }
- }
- }
- }
- void _solve(){
- //addEdge between pi(i,j) and pi(x,y) such that v[i][j], v[x][y] sea letra
- //max(abs(i-x), abs(j-y)) <= d
- rep(i, 0, n){
- rep(j, 0, m){
- char c = v[i][j];
- if(c != '.' and c != 'C')
- rep(k, 0, n){
- rep(l, 0, m){
- char c2 = v[k][l];
- if(c2 != '.' and c != 'C'){
- int dist = max(abs(i-k), abs(j-l));
- if(dist <= d){
- int n1 = i*m + j,
- n2 = k*m + l;
- g[n1].push_back(n2);
- g[n2].push_back(n1);
- }
- }
- }
- }
- }
- }
- dfs();
- rep(i, 0, n){
- rep(j, 0, m){
- char c = v[i][j];
- if(c != '.' and c != 'C'){
- if(vis[ind(pi(i, j))]) c = '*';
- }
- cout << c;
- }
- cout << endl;
- }
- }
- void _input(){
- cin >> n >> m >> d;
- vector<vector<char>> a(n, vector<char> (m));
- rep(i, 0, n)
- rep(j, 0, m){
- cin >> a[i][j];
- if(a[i][j] == 'C') ch = pi(i, j);
- else if(a[i][j] == 'X') xx = pi(i, j);
- }
- v = a;
- g = vector<vector<int>> (n*m);
- vis = vector<bool> (n*m, false);
- }
- int main()
- {
- while(q--){
- _input();
- _solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement