2020 CCPC绵阳站G.Game of Cards(博弈搜索)

G .Game of Cards

G. Game of Cards
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Little Rabbit and Little Horse love playing odd card games. Now, they are playing a card game called 0123−game.

There are several cards on the table. c0 of them are labeled with 0, c1 of them are labeled with 1, c2 of them are labeled with 2, and c3 of them are labeled with 3. Little Rabbit and Little Horse take turns to play the game, and Little Rabbit goes first. In each turn, the player should choose two cards on the condition that the sum of the numbers on the two cards is no more than 3, then replace these two cards with a card labeled with their sum. The player who cannot make a move loses the game.

Little Rabbit and Little Horse wonder who will win the game.

Input
The first line of the input contains an integer T (1≤T≤105) — the number of test cases.

Each test case contains four integers c0,c1,c2,c3 (0≤c0,c1,c2,c3≤109) — the number of cards labeled with 0,1,2,3.

Output
For the x-th test case, if Little Rabbit wins, output Case #x: Rabbit in a single line. Otherwise, output Case #x: Horse in a single line.

Example
inputCopy
2
1 1 1 1
2 2 2 2
outputCopy
Case #1: Horse
Case #2: Rabbit

官方题解截图:

在这里插入图片描述
在这里插入图片描述

我选择了解法2(毕竟搜索不用动脑子

#include<bits/stdc++.h>
int dfs(int c0, int c1, int c2, int c3)
{
    if (c0 == 0 && c1 == 0)return 0;
    if (c0 == 0 && c2 == 0 && c1 < 2)return 0;
    if (c0 > 0 && !dfs(c0 - 1, c1, c2, c3))return 1;
    if (c1 >= 2 && !dfs(c0, c1 - 2, c2 + 1, c3))return 1;
    if (c1 > 0 && c2 > 0 && !dfs(c0, c1 - 1, c2 - 1, c3 + 1))return 1;
    return 0;
}
int main()
{
    int t;
    scanf("%d", &t);
    int cas = 0;
    while (t--)
    {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int win = -1;
        if (b == 0 && c == 0 && d == 0) {
            if (a == 0)win = 0;
            else if (a & 1)win = 0;
            else win = 1;
        }
        else win = dfs(a % 2, b % 3, c, d);
        printf("Case #%d: %s\n", ++cas, win ? "Rabbit" : "Horse");
    }
    return 0;
}
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值