Guest User

Untitled

a guest
Jul 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8. typedef vector<double> VD;
  9. typedef vector<int> VI;
  10. typedef vector<bool> VB;
  11. typedef vector<vector<int> > MI;
  12. typedef vector<vector<bool> > MB;
  13.  
  14. void posauns(MB &uns,int i, bool fila)
  15. {
  16. if(fila)
  17. {
  18. for(int j=0;j<8;j++)
  19. {
  20. uns[i][j]=1;
  21. }
  22.  
  23. }
  24. else {
  25. for(int j=0;j<8;j++)
  26. {
  27. uns[j][i]=1;
  28. }
  29.  
  30. }
  31.  
  32.  
  33. }
  34. bool ame(MI reines,int i,int fila, int columna)
  35. {
  36. MB amenasa(8,VB(8,0));
  37. for(int j=0;j<i;j++)
  38. {
  39. int n,m,d1,d2;
  40. n=reines[j][0];
  41. m=reines[j][1];
  42. posauns(amenasa,n,1);
  43. posauns(amenasa,m,0);
  44. d1=m+n;
  45. d2=m-n;
  46. for(int k=0;k<8;k++)
  47. {
  48. for(int s=0;s<8;s++)
  49. {
  50. if(s+k==d1) amenasa[k][s]=1;
  51. if(k-s==d2) amenasa[k][s]=1;
  52. }
  53. }
  54.  
  55. }
  56.  
  57. return amenasa[fila][columna];
  58. }
  59.  
  60.  
  61. void reines(int i,VB &usat,MI &rei)
  62. {
  63. if(i<8){
  64. for(int j=0;j<8;j++)
  65. {
  66. if(not usat[j])
  67. {
  68. usat[j]=1;
  69. for(int k=0;k<8;k++)
  70. {
  71. if(not ame(rei,i,j,k))
  72. {
  73. rei[i][0]=j;
  74. rei[i][1]=k;
  75. reines(i+1,usat,rei);
  76. }
  77.  
  78. }
  79. usat[j]=0;
  80. }
  81.  
  82. }
  83.  
  84.  
  85. }
  86.  
  87.  
  88. else {
  89. for(int i=0;i<8;i++)
  90. {
  91. for(int j=0;j<2;j++)
  92. {
  93. cout << rei[i][j] << " ";
  94.  
  95. }
  96. cout << endl;
  97.  
  98.  
  99. }
  100. }
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107. int main()
  108. {
  109. VB usat(8,0);
  110. MI rei(8,VI(2,0));
  111. reines(0,usat,rei);
  112.  
  113.  
  114.  
  115. }
Add Comment
Please, Sign In to add comment