原题链接:Problem - 7216
题目描述:
Problem Description
Kate and Emilico are playing a game. There are 3 integers a,b,c. It is guaranteed that there exists a non-degenerate triangle whose side lengths are a,b,c respectively. The game goes as follows. Players take turns in decreasing a certain positive integer on one of the 3 integers. If there doesn't exist a non-degenerate triangle whose side lengths are a,b,c after a player's operation, the player loses.
Kate goes first. If both of them play optimally, will Kate win?
Input
The first line of input contains one integer T (1≤T≤104), indicating the number of test cases.
For each test case, the only line contains 3 integers a,b,c (1≤a,b,c≤109). It is guaranteed that there exists a non-degenerate triangle whose side lengths are a,b,c respectively.
Output
For each test case, if Kate will win, output Win in a single line. Otherwise, output Lose in a single line.
Sample Input
3 2 2 3 2 3 4 5 3 4
Sample Output
Win
Lose
Win
题目大意:
给定三角形的三条边,Kate和Emilico轮流行动,每次行动选择一条边减去任意正整数,当一位玩家行动完毕之后三个数不能组成又给三角形,则该玩家失败。Kate先手,请问双方都使用最优策略时Kate是否可以赢。
解题思路:
博弈问题,可以转化为nim问题。
结论是:Kate 获胜当且仅当(a - 1) ^ (b - 1) ^ (c - 1) = 0。其中^为异或运算。
代码(CPP):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e3 + 10;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--)
{
int a, b, c;
cin >> a >> b >> c;
cout << ((a - 1) ^ (b - 1) ^ (c - 1) ? "Win\n" : "Lose\n");
}
return 0;
}