首页 > 其他 > 详细

[CCPC2020绵阳G] Game of Cards - 博弈,找规律

时间:2021-04-12 18:00:34      阅读:22      评论:0      收藏:0      [点我收藏+]

[CCPC2020绵阳G] Game of Cards - 博弈

Description

数字0,1,2,3各有一些数目,每次可以取两个数字和小于等于3,然后替换成其和。不能选数的人输了。求先手是否必胜。

Solution

首先用 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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!