您的位置:首页 > 其它

中国象棋将帅问题

2018-03-26 09:34 120 查看
将帅不能在一条主线上,直接穷举所有的位置

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main(int argc, char **argv) {
int t = 1;
int b[3][3];
int a[3][3];
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
a[i][j] = t;
b[i][j] = t++;
}
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
for (int z = 0; z < 3; ++z)
for (int c = 0; c < 3; ++c) {
if (b[z][c] % 3 != a[i][j])
printf("A=%d,B=%d\n", a[i][j], b[z][c]);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: