数字0,1,2,3各有一些数目,每次可以取两个数字和小于等于3,然后替换成其和。不能选数的人输了。求先手是否必胜。
首先用 4 维 dp 打出一个表,然后很容易发现规律
注意:把 0 直接去掉最后改奇偶性是不对的
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define first "Rabbit"
#define second "Horse"
int caseid = 0;
void print(int x)
{
if (x == 1)
cout << first << endl;
else
cout << second << endl;
}
void solve()
{
int c0, c1, c2, c3;
cin >> c0 >> c1 >> c2 >> c3;
++caseid;
cout << "Case #" << caseid << ": ";
if (c0 == 0 && c1 == 0 && c2 == 0 && c3 == 0)
{
print(0);
}
else if (c1 == 0 && c2 == 0 && c3 == 0)
{
print(c0 % 2 == 0);
}
else
{
int ans = 0;
int i = c1, j = c2;
if (i % 3 == 0)
ans = 0;
if (i % 3 == 1)
ans = j > 0;
if (i % 3 == 2)
ans = (c0 & 1) ? j < 2 : 1;
ans ^= c0 & 1;
print(ans);
}
}
signed main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
solve();
}
[CCPC2020绵阳G] Game of Cards - 博弈,找规律
原文:https://www.cnblogs.com/mollnn/p/14648234.html