#18911: 為什麼WA


51xg12@ms.mingdao.edu.tw (洪祐鈞)

學校 : 臺中市私立明道高級中學
編號 : 73177
來源 : [39.12.166.40]
最後登入時間 :
2019-10-15 17:19:16
d324. 00750 - 8 Queens Chess Problem -- UVa750 | From: [39.8.71.236] | 發表日期 : 2019-08-13 21:21

#include <iostream>
using namespace std;
int scale, input_y, input_x, ct, sol[9];
bool check_x[9], check_y[9], check_d1[15], check_d2[15];

void backtrack(int y)
{

if (y > 8)
{
cout << "\n";
cout << " " << ct << " ";
ct++;
for (int i = 1;i < 9;++i)
{
cout << sol[i] << " ";
}
}
else if (y == input_y)
{
sol[y] = input_x;
backtrack(y + 1);
}
else
{
for (int x = 1;x < 9;++x)
{
int d1 = (x + y - 2), d2 = (x - y + 7);//check diagonal
check_x[input_x] = check_d1[(input_x + input_y - 2)] = check_d2[input_x - input_y + 7] = true;

if (!check_x[x] && !check_d1[d1] && !check_d2[d2])
{
check_x[x] = check_d1[d1] = check_d2[d2] = true;
sol[y] = x;
backtrack(y + 1);
check_x[x] = check_d1[d1] = check_d2[d2] = false;
}
}
}
}

int main()
{
cin >> scale;

while (scale-- && cin >> input_y >> input_x)
{
cout << "SOLN COLUMN" << "\n" << " # 1 2 3 4 5 6 7 8" << "\n";
for (int i = 0;i < 15;i++)
{
check_d1[i] = check_d2[i] = 0;
}//init
for (int i = 0;i < 9;i++)
{
check_x[i] = check_y[i] = sol[i] = 0;
}//init
ct = 1;
backtrack(1);
cout << "\n";
}
}

錯在LINE:9

 

 

 
ZeroJudge Forum