中国象棋将帅问题
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;
}
#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;
}
相关文章推荐
- 第一章 游戏之乐 中国象棋将帅问题
- 编程之美:中国象棋将帅问题
- 《编程之美》读书笔记(一):中国象棋将帅问题
- 1.2 中国象棋将帅问题进一步讨论与扩展:如何用1个变量实现N重循环?[chinese chess]
- 第1章 游戏之乐——中国象棋将帅问题
- 【编程之美】中国象棋将帅问题
- 《编程之美》读书笔记(1)--中国象棋将帅问题
- 【编程之美读书笔记】中国象棋将帅问题
- 中国象棋将帅问题
- 《编程之美》读书笔记(一):中国象棋将帅问题
- 编程之美1.2中国象棋将帅问题
- 《编程之美》学习笔记 中国象棋将帅问题
- 编程之美之1.2 中国象棋将帅问题
- 【算法习作】中国象棋将帅问题
- 编程之美 — 中国象棋将帅问题
- 编程之美——中国象棋将帅问题
- 《编程之美》1.2 中国象棋将帅问题 学习笔记
- 【编程之美】中国象棋将帅问题
- (1.5.1.2)编程之美:中国象棋将帅问题——一个变量实现多重循环
- 中国象棋将帅问题----《编程之美》读书笔记