Guest User

Untitled

a guest
Jun 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3.  
  4. enum{PLAQUE,COTE};
  5.  
  6. int LAdj[13][6][2]={{{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  7. {{0,0},{2,3},{3,3},{4,3},{5,3},{6,3}}, //1
  8. {{0,0},{11,1},{3,4},{1,1},{6,2},{7,5}}, //2
  9. {{0,0},{10,1},{4,4},{1,2},{2,2},{11,5}}, //3
  10. {{0,0},{9,1},{5,4},{1,3},{3,2},{10,5}}, //4
  11. {{0,0},{8,1},{6,4},{1,4},{4,2},{9,5}}, //5
  12. {{0,0},{7,1},{2,4},{1,5},{5,2},{8,5}}, //6
  13. {{0,0},{6,1},{8,4},{12,3},{11,2},{2,5}}, //7
  14. {{0,0},{5,1},{9,4},{12,4},{7,2},{6,5}}, //8
  15. {{0,0},{4,1},{10,4},{12,5},{8,2},{5,5}}, //9
  16. {{0,0},{3,1},{11,4},{12,1},{9,2},{4,5}}, //10
  17. {{0,0},{2,1},{7,4},{12,2},{10,2},{3,5}}, //11
  18. {{0,0},{10,3},{11,3},{7,3},{8,3},{9,3}}};//12
  19. int couleurs[13][6];
  20. int etat[13][2];
  21. bool dejaVu[13];
  22.  
  23. void print(){
  24. for(int plaque=1;plaque<=12;plaque++){
  25. printf("%d ",etat[plaque][PLAQUE]);
  26. int Rota=etat[plaque][COTE];
  27. if(Rota!=0)
  28. Rota=5-Rota;
  29. printf("%d\n",LAdj[plaque][1+Rota][PLAQUE]);
  30. }
  31. }
  32.  
  33. bool possible(int place,int plaque,int rota){
  34. for(int cote=1;cote<=5;cote++){
  35. if(etat[LAdj[place][cote][PLAQUE]][PLAQUE]!=0){
  36.  
  37. int couleur=couleurs[plaque][((cote+rota-1)%5)+1];
  38.  
  39. int autrePlaque=etat[LAdj[place][cote][PLAQUE]][PLAQUE];
  40. int autreRota=etat[LAdj[place][cote][PLAQUE]][COTE];
  41. int autreCote=LAdj[place][cote][COTE];
  42. int autreCol=couleurs[autrePlaque][((autreCote+autreRota-1)%5)+1];
  43. if(couleur!=autreCol)
  44. return false;
  45. }
  46. }
  47. return true;
  48. }
  49.  
  50. void backTrack(int aPlacer){
  51. if(aPlacer==13){
  52. print();
  53. exit(0);
  54. }
  55. else{
  56. for(int plaque=1;plaque<=12;plaque++){
  57. for(int rota=0;rota<5;rota++){
  58. int Rota=0;
  59. if(rota!=0)
  60. Rota=5-rota;
  61. if(!dejaVu[plaque] && possible(aPlacer,plaque,Rota)){
  62. etat[aPlacer][PLAQUE]=plaque;
  63. etat[aPlacer][COTE]=Rota;
  64. dejaVu[plaque]=true;
  65. backTrack(aPlacer+1);
  66. dejaVu[plaque]=false;
  67. etat[aPlacer][PLAQUE]=0;
  68. }
  69. }
  70. }
  71. }
  72. }
  73.  
  74. int main(void){
  75. for(int plaque=1;plaque<=12;plaque++)
  76. for(int cote=1;cote<=5;cote++)
  77. scanf("%d",&couleurs[plaque][cote]);
  78.  
  79. backTrack(1);
  80. printf("-1\n");
  81. }
Add Comment
Please, Sign In to add comment