Created
October 13, 2014 00:35
-
-
Save ealmansi/3a5498f245d86ac21866 to your computer and use it in GitHub Desktop.
PLP coloreo
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
#include <iostream> | |
#include <iomanip> | |
using namespace std; | |
// fuerza bruta | |
int main(int argc, char const *argv[]) | |
{ | |
string cs[] = {"rojo", "azul", "amarillo", "verde"}; | |
int vs[][2] = { | |
{1, 2}, {1, 3}, {1, 4}, {1, 5}, | |
{2, 3}, {2, 4}, | |
{3, 4}, | |
{4, 5} | |
}, vs_len = sizeof(vs)/sizeof(vs[0]); | |
int ps[6], ps_len = sizeof(ps)/sizeof(ps[0]); | |
int cant_soluciones = 0, temp; | |
bool ok; | |
cout << setiosflags(ios::fixed) << left; | |
for (int j = 1; j < ps_len; ++j) { | |
cout << setw(9) << "color" << j; | |
if (j + 1 < ps_len) cout << "|"; | |
} cout << endl; | |
cout << endl; | |
for (int i = 0; i < 1024 /*4^5*/; ++i) { | |
temp = i; | |
for (int j = 1; j < ps_len; ++j) { | |
ps[j] = temp % 4, temp = temp / 4; | |
} | |
ok = true; | |
for (int j = 0; j < vs_len && ok; ++j) { | |
if (ps[vs[j][0]] == ps[vs[j][1]]) { | |
ok = false; | |
} | |
} | |
if (ok) { | |
for (int j = 1; j < ps_len; ++j) { | |
cout << setw(10) << cs[ps[j]]; | |
if (j + 1 < ps_len) cout << "|"; | |
} cout << endl; | |
++cant_soluciones; | |
} | |
} | |
cout << endl; | |
cout << "Cantidad de soluciones: " << cant_soluciones << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment