本文主要是介绍孔明棋,(n + 2) x (m + 2)的棋盘,中间n x m的区域都是棋子,求最后最少剩余几个棋子,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目
#include <iostream>
using namespace std;
int f(int n, int m)
{int t, res;if (n > m){t = n;n = m;m = t;}if (n == 1)res = (m + 1) / 2;else if (n == 2){if (m % 3 == 0)res = 2;elseres = 1;}else if (n == 3){res = 2;}return res;
}
int change(int x)
{x %= 3;if (x == 0)x += 3;return x;
}
int main()
{int T, n, m, i, j;cin >> T;while (T--){cin >> n >> m;int t;if (n > m)t = n, n = m, m = t;if (n <= 3)cout << f(n, m) << '\n';else{if (n % 3 == 0 || m % 3 == 0)cout << 2 << '\n';elsecout << 1 << '\n';}}return 0;
}
这篇关于孔明棋,(n + 2) x (m + 2)的棋盘,中间n x m的区域都是棋子,求最后最少剩余几个棋子的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!