Skip to content

Instantly share code, notes, and snippets.

@ealmansi
Created October 13, 2014 00:35
Show Gist options
  • Save ealmansi/3a5498f245d86ac21866 to your computer and use it in GitHub Desktop.
Save ealmansi/3a5498f245d86ac21866 to your computer and use it in GitHub Desktop.
PLP coloreo
#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