Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int dx[] = {1, 0, -1, 0};
- int dy[] = {0, 1, 0, -1};
- bool esValido(int x, int y)
- {
- return 0 <= x && x < 4 && 0 <= y && y < 4;
- }
- string plastetris(vector <string> cajita)
- {
- /**
- Genero todos los tableros válidos
- y luego compruebo si alguno es igual al input
- **/
- vector <vector <vector <string> > > tableros(4);
- vector <string> tableroVacio = {"....", "....", "....", "...."};
- for(int i=0; i<4; i++)
- {
- for(int j=0; j<4; j++)
- {
- tableroVacio[i][j] = 'X';
- tableros[0].push_back(tableroVacio);
- tableroVacio[i][j] = '.';
- }
- }
- for(int i=1; i<tableros.size(); i++)
- {
- for(int j=0; j<tableros[i-1].size(); j++)
- {
- /**
- Por cada tablero, pruebo convertir
- un '.' en una 'X'
- solo si tiene una vecina que ya es X
- **/
- auto tablero = tableros[i-1][j];
- for(int x=0; x<4; x++)
- {
- for(int y=0; y<4; y++)
- {
- if(tablero[x][y] == '.')
- {
- bool valido = false;
- for(int k=0; k<4; k++)
- {
- int x2 = x+dx[k];
- int y2 = y+dy[k];
- if(esValido(x2, y2) && tablero[x2][y2] == 'X')
- {
- valido = true;
- break;
- }
- }
- if(valido == true)
- {
- tablero[x][y] = 'X';
- tableros[i].push_back(tablero);
- tablero[x][y] = '.';
- }
- }
- }
- }
- }
- }
- for(int i=0; i<tableros[3].size(); i++)
- if(tableros[3][i] == cajita)
- return "SI";
- return "NO";
- }
- /**
- //Función main auxiliar para testear
- int main()
- {
- vector <string> cajita(4);
- for(int i=0; i<4; i++)
- cin >> cajita[i];
- cout << plastetris(cajita) << endl;
- return 0;
- }
- **/
Advertisement
Add Comment
Please, Sign In to add comment