Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <iostream>
- #include <cmath>
- using namespace std;
- typedef vector<double> VD;
- typedef vector<int> VI;
- typedef vector<bool> VB;
- typedef vector<vector<int> > MI;
- typedef vector<vector<bool> > MB;
- void posauns(MB &uns,int i, bool fila)
- {
- if(fila)
- {
- for(int j=0;j<8;j++)
- {
- uns[i][j]=1;
- }
- }
- else {
- for(int j=0;j<8;j++)
- {
- uns[j][i]=1;
- }
- }
- }
- bool ame(MI reines,int i,int fila, int columna)
- {
- MB amenasa(8,VB(8,0));
- for(int j=0;j<i;j++)
- {
- int n,m,d1,d2;
- n=reines[j][0];
- m=reines[j][1];
- posauns(amenasa,n,1);
- posauns(amenasa,m,0);
- d1=m+n;
- d2=m-n;
- for(int k=0;k<8;k++)
- {
- for(int s=0;s<8;s++)
- {
- if(s+k==d1) amenasa[k][s]=1;
- if(k-s==d2) amenasa[k][s]=1;
- }
- }
- }
- return amenasa[fila][columna];
- }
- void reines(int i,VB &usat,MI &rei)
- {
- if(i<8){
- for(int j=0;j<8;j++)
- {
- if(not usat[j])
- {
- usat[j]=1;
- for(int k=0;k<8;k++)
- {
- if(not ame(rei,i,j,k))
- {
- rei[i][0]=j;
- rei[i][1]=k;
- reines(i+1,usat,rei);
- }
- }
- usat[j]=0;
- }
- }
- }
- else {
- for(int i=0;i<8;i++)
- {
- for(int j=0;j<2;j++)
- {
- cout << rei[i][j] << " ";
- }
- cout << endl;
- }
- }
- }
- int main()
- {
- VB usat(8,0);
- MI rei(8,VI(2,0));
- reines(0,usat,rei);
- }
Add Comment
Please, Sign In to add comment