Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- enum{PLAQUE,COTE};
- int LAdj[13][6][2]={{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
- {{0,0},{2,3},{3,3},{4,3},{5,3},{6,3}}, //1
- {{0,0},{11,1},{3,4},{1,1},{6,2},{7,5}}, //2
- {{0,0},{10,1},{4,4},{1,2},{2,2},{11,5}}, //3
- {{0,0},{9,1},{5,4},{1,3},{3,2},{10,5}}, //4
- {{0,0},{8,1},{6,4},{1,4},{4,2},{9,5}}, //5
- {{0,0},{7,1},{2,4},{1,5},{5,2},{8,5}}, //6
- {{0,0},{6,1},{8,4},{12,3},{11,2},{2,5}}, //7
- {{0,0},{5,1},{9,4},{12,4},{7,2},{6,5}}, //8
- {{0,0},{4,1},{10,4},{12,5},{8,2},{5,5}}, //9
- {{0,0},{3,1},{11,4},{12,1},{9,2},{4,5}}, //10
- {{0,0},{2,1},{7,4},{12,2},{10,2},{3,5}}, //11
- {{0,0},{10,3},{11,3},{7,3},{8,3},{9,3}}};//12
- int couleurs[13][6];
- int etat[13][2];
- bool dejaVu[13];
- void print(){
- for(int plaque=1;plaque<=12;plaque++){
- printf("%d ",etat[plaque][PLAQUE]);
- int Rota=etat[plaque][COTE];
- if(Rota!=0)
- Rota=5-Rota;
- printf("%d\n",LAdj[plaque][1+Rota][PLAQUE]);
- }
- }
- bool possible(int place,int plaque,int rota){
- for(int cote=1;cote<=5;cote++){
- if(etat[LAdj[place][cote][PLAQUE]][PLAQUE]!=0){
- int couleur=couleurs[plaque][((cote+rota-1)%5)+1];
- int autrePlaque=etat[LAdj[place][cote][PLAQUE]][PLAQUE];
- int autreRota=etat[LAdj[place][cote][PLAQUE]][COTE];
- int autreCote=LAdj[place][cote][COTE];
- int autreCol=couleurs[autrePlaque][((autreCote+autreRota-1)%5)+1];
- if(couleur!=autreCol)
- return false;
- }
- }
- return true;
- }
- void backTrack(int aPlacer){
- if(aPlacer==13){
- print();
- exit(0);
- }
- else{
- for(int plaque=1;plaque<=12;plaque++){
- for(int rota=0;rota<5;rota++){
- int Rota=0;
- if(rota!=0)
- Rota=5-rota;
- if(!dejaVu[plaque] && possible(aPlacer,plaque,Rota)){
- etat[aPlacer][PLAQUE]=plaque;
- etat[aPlacer][COTE]=Rota;
- dejaVu[plaque]=true;
- backTrack(aPlacer+1);
- dejaVu[plaque]=false;
- etat[aPlacer][PLAQUE]=0;
- }
- }
- }
- }
- }
- int main(void){
- for(int plaque=1;plaque<=12;plaque++)
- for(int cote=1;cote<=5;cote++)
- scanf("%d",&couleurs[plaque][cote]);
- backTrack(1);
- printf("-1\n");
- }
Add Comment
Please, Sign In to add comment