-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9aa64e
commit c343e18
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Nombre del alumno Juan Romo Iribarren | ||
// Usuario del Juez F59 | ||
|
||
#include <iostream> | ||
#include <iomanip> | ||
#include <fstream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int reinas(int N, int r, vector<bool>& filas, vector<bool>& diagAsc, vector<bool>& diagDesc) { | ||
if (r == 0) { | ||
return 1; | ||
} | ||
else { | ||
int maneras = 0; | ||
|
||
for (int i = 0; i < N; i++) { | ||
if (!filas[i] && !diagAsc[i + N - r] && !diagDesc[2 * N - r - i - 1]) { | ||
filas[i] = true; | ||
diagAsc[i + N - r] = true; | ||
diagDesc[2 * N - r - i - 1] = true; | ||
maneras += reinas(N, r - 1, filas, diagAsc, diagDesc); | ||
filas[i] = false; | ||
diagAsc[i + N - r] = false; | ||
diagDesc[2 * N - r - i - 1] = false; | ||
} | ||
} | ||
|
||
return maneras; | ||
} | ||
} | ||
|
||
// Resuelve un caso de prueba, leyendo de la entrada la | ||
// configuración, y escribiendo la respuesta | ||
void resuelveCaso() { | ||
// leer los datos de la entrada | ||
int N; | ||
cin >> N; | ||
|
||
vector<bool> filas(N, false); | ||
vector<bool> diagAsc(2 * N - 1, false); | ||
vector<bool> diagDesc(2 * N - 1, false); | ||
cout << reinas(N, N, filas, diagAsc, diagDesc) << '\n'; | ||
} | ||
|
||
int main() { | ||
// Para la entrada por fichero. | ||
// Comentar para acepta el reto | ||
#ifndef DOMJUDGE | ||
std::ifstream in("datos.txt"); | ||
auto cinbuf = std::cin.rdbuf(in.rdbuf()); //save old buf and redirect std::cin to casos.txt | ||
#endif | ||
|
||
|
||
int numCasos; | ||
std::cin >> numCasos; | ||
for (int i = 0; i < numCasos; ++i) | ||
resuelveCaso(); | ||
|
||
|
||
// Para restablecer entrada. Comentar para acepta el reto | ||
#ifndef DOMJUDGE // para dejar todo como estaba al principio | ||
std::cin.rdbuf(cinbuf); | ||
system("PAUSE"); | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
2 | ||
3 | ||
4 |
Binary file not shown.