2022“杭电杯”中国大学生算法设计超级联赛(7)1004 Triangle Game

原题链接: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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值