#include <iostream>using namespace std;const int o = 9;int r[9];bool c[9];bool k_1[17];bool k_minus1[17];char stage[9][9];void tryR(int i){ if (i == 9) { for (int k = 1; k < 9 ;k++) cout << r[k] << " "; exit(0); } for (int j = 1; j < 9; j++) { if (stage[i][j] != '#' && c[j] && k_1[i - j + o] && k_minus1[i + j]) { r[i] = j; c[j] = false; k_1[i - j + o] = false; k_minus1[i + j] = false; tryR(i + 1); k_minus1[i + j] = true; k_1[i - j + o] = true; c[j] = true; } }}int main(){ for (int i = 1; i < 9; i++) { c[i] = true; for (int j = 1; j < 9; j++) { cin >> stage[i][j] ; k_1[i - j + o] = true; k_minus1[i + j] = true; } } tryR(1); return 0;} C忘得差不多了 怎么改呢 还有for循环换成while 就会死循环 怎么解决 求解求解
- 4 回答
- 1 关注
- 1804 浏览
添加回答
举报
0/150
提交
取消