#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<utility> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; vector<string> grilla; vector< pair<int, int> > m; void dfs(char marcar,int x, int y) { if (x >= 0 && x < grilla.size() && y >= 0 && y < grilla[x].size() && grilla[x][y] == 32) { grilla[x][y] = marcar; dfs(marcar, x - 1, y); dfs(marcar, x, y - 1); dfs(marcar, x + 1, y); dfs(marcar, x, y + 1); } } int main() { #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif int len = 0; char linea[100]; while (gets(linea) != NULL) { if (linea[0] == '_') { int n = m.size(); for (int i = 0; i < n; i++) { char marcar = grilla[m[i].first][m[i].second]; grilla[m[i].first][m[i].second] = 32; dfs(marcar, m[i].first, m[i].second); } n = grilla.size(); for (int i = 0; i < n; i++) { printf("%s\n", grilla[i].c_str()); } puts(linea); grilla.clear(); m.clear(); continue; } len = strlen(linea); for (int i = 0; i < len; i++) { if (linea[i] != 32 && linea[i] != 'X') m.push_back(make_pair(grilla.size(), i)); } grilla.push_back(linea); } return 0; }
domingo, 1 de abril de 2012
785 - Grid Colouring, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario