【博弈论】HDU - 7216 Triangle Game

思路

先说结论:若 \((a-1)\otimes(b-1)\otimes (c-1)\ne 0\) 则先手必胜\(\otimes\) 代表异或)

假设 \(a\le b \le c\),那么有 \(a+b\ge c\),则有 \((a-1)+(b-1)\ge (c-1)\)

\(x = (a-1)\otimes (b-1)\otimes (c-1)\)

\(x=0:\)

  • \(a=1\),那么此时有 \((b-1)\otimes (c-1)=0\to a<b=c\)\(a\) 已经不能再减小了,此时无论减少 \(b\) 还是 \(c\) 都无发构成三角形。

  • \(a>1\),假设将 \(a\to a'\),此时有 \((a'-1)\ne (a-1)\to (a'-1)\otimes (b-1)\otimes (c-1)\ne 0\),即转变到 \(x\ne 0\) 情况。

\(x\ne 0\):

  • 三个不等式必有一个成立 \((a-1)\otimes x < (a-1),(b-1)\otimes x < (b-1),(c-1)\otimes x < (c-1).\)
  • 因为 \(x\) 中的 \(1\)\((a-1),(b-1),(c-1)\) 由三者异或得到的,也就是一定是奇数次的 \(1\) 的个数,那么不妨假设最高位的 \(1\) 是由 \((a-1)\) 提供的,(另外两个即便也有 \(1\),也会因为异或偶数次而被抵消 ),那么我们 \(x\) 的这一位上也一定有 \(1\),让 \(x\otimes (a-1)\),就可以抵消最高位的 \(1\) ,使得其小于 \((a-1)\)。所以一定会存在由 \(x\ne 0\to x=0\) 的情况,也就是由必胜态转向必败态。

在两人都采取最优策略的情况下,那么先手就可以决定胜败。

代码

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int a, b, c;
cin >> a >> b >> c;
cout << ((a - 1) ^ (b - 1) ^ (c - 1) ? "Win" : "Lose") << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

本文作者:Ke_scholar

本文链接:https://www.cnblogs.com/Kescholar/p/18366543

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Ke_scholar  阅读(14)  评论(0编辑  收藏  举报
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示