洛谷P1488 肥猫的游戏
url: https://www.luogu.com.cn/problem/P1488
tag:
博弈论,模拟
思路:我觉得比起博弈论,更像是模拟题。这道题先是判断黑色三角形的位置,通过判断是不是有两条边为多边形的边界,如果是,说明先手可以直接切。如果不是,就继续判断n-5的奇偶性,n-5是三角形的个数,表示切了n-5个,这个数是因为一种特殊情况,当场上只有三个三角形的时候,且黑色不是在外层,这个时候如果先手切了一个,那么后手必胜,反之后手切了一个则先手必胜。一共有n-2个三角形,除去最后3个,一共是n-5个,表示进行了n-5次操作,如果为偶数次,说明第n-5次操作是后手,那么第n-4次就是先手,后手必胜,反之如果是奇数次,说是第n-5次操作时先手,那么第n-4次就是后手,先手必胜。总结一下就是当n-5为偶数后手胜,为奇数先手胜。
代码:
#include <iostream>
#include <cmath>
using namespace std;
int n, x, y, z;
int main()
{
cin >> n;
cin >> x >> y >> z;
int cnt = 0;
if (abs(x - y) == 1 || abs(x - y) == n - 1) cnt ++;
if (abs(x - z) == 1 || abs(x - z) == n - 1) cnt ++;
if (abs(y - z) == 1 || abs(y - z) == n - 1) cnt ++;
if (cnt == 2)
{
cout << "JMcat Win";
return 0;
}
if ((n - 5) % 2) cout << "JMcat Win";
else cout << "PZ Win";
return 0;
}