【题解】ZOJ-3057 Beans Game
Beans Game(ZOJ-3057)
题面
There are three piles of beans. TT and DD pick any number of beans from any pile or the same number from any two piles by turns. Who get the last bean will win. TT and DD are very clever.
输入
Each test case contains of a single line containing 3 integers a b c, indicating the numbers of beans of these piles. It is assumed that 0 <= a,b,c <= 300 and a + b + c > 0.
输出
For each test case, output 1 if TT will win, ouput 0 if DD will win.
样例输入
1 | 1 0 0 |
样例输出
1 | 1 |
提示
无
思路
对于先手来说,如果数量分别为(a, a, b)或(a, b, a),或(b, a, a)的形式,那么先手必赢,因为先手可以使其成为(a, a, a)的形式,那么不论后手怎么拿,都是先手最后使其成为(a, a, a)的形式直至(0, 0, 0);如果(a, b, c)是必败态,那么将其中某个数加k,或将其中某两个数同时加k,就是必胜态。
1 | using namespace std; |