8 Queens Chess Problem

题目:八皇后模型,输出包含了某一点的所有皇后 注意:格式上,不同输入之间空两行。数字的最后没有空格,所以把空格写在前面。还有最后一行输出后,后面没有空行了 #

题目:八皇后模型,输出包含了某一点的所有皇后

注意:格式上,不同输入之间空两行。数字的最后没有空格,所以把空格写在前面。还有最后一行输出后,后面没有空行了

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;int main()
{int xunhuan;cin>> xunhuan;while(xunhuan--){int x,y;cin >> x >> y;int t = 1;int a[8] = {0};int b[15] = {0};int c[15] = {0};int j = 0,i=0;int temp = 0;int count = 1;vector m;vector::iterator it;vector sum;cout<<"SOLN       COLUMN"<= 0){i--;temp = m[i];//删除原来皇后的记录a[temp]=0;b[i+temp]=0;c[i-temp+7]=0;m.pop_back();for(j = temp +1; j <= 7; j ++){if((a[j]==0) && (b[i+j]==0) && (c[i-j+7]==0) ){//这一点可以有皇后m.push_back(j);a[j]=1;b[i+j]=1;c[i-j+7]=1;break;}}if(j != 8) break;}}}}//判断if(m[y-1] == x-1){printf("%2d",count++);cout<<"     ";for(it = m.begin();it != m.end();it++){cout << " " << (*it)+1; //空格在之前出现}cout<