#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<set> #include<algorithm> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl #define listar(lista) for (int i = 0; i < lista.size(); i++) db(lista[i]) #define foreach(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++) using namespace std; int dirx[] = {0, 0, -1, 1}; int diry[] = {-1, 1, 0, 0}; vector<string> matriz; int n; void llenar (int x, int y) { if (x < 0 || x >= n || y < 0 || y >= n || matriz[x][y] != '.') return; for (char i = 'A'; i < 'Z' + 1; i++) { bool can = true; for (int k = 0; k < 4; k++) { if (x + dirx[k] >= 0 && x + dirx[k] < n && y + diry[k] >= 0 && y + diry[k] < n && matriz[x + dirx[k]][y + diry[k]] == i) can = false; } if (can) { matriz[x][y] = i; break; } } } int main() { int t, caso; #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif scanf("%d", &t); caso = t; while (t--) { scanf("%d", &n); matriz.resize(n); for (int i = 0; i < n; i++) { cin >> matriz[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { llenar(i, j); } } printf("Case %d:\n", caso - t); for (int i = 0; i < n; i++) { cout << matriz[i] << endl; } } return 0; }
domingo, 18 de noviembre de 2012
11520 - Fill the Square, uva, solution
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario