牛客网 - Ricky’s RealDan’s Ricky(博弈)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lzyws739307453/article/details/85474924

题目链接:https://ac.nowcoder.com/acm/contest/322/H
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述 

The 2019 is coming!Ricky 和 RealDan为了庆祝2018一年的成果,准备去大吃一顿,然而Ricky 想吃火锅, RealDan 想吃海鲜。为了解决吃什么的难题, 他们向聪明的神秘人(出题人)寻求帮助,神秘人则给他们出了这样一个问题:
现在有 n 个娃娃机,第i(1 <= i <= n) 个娃娃机中有 a[i] 个娃娃。
规则如下:
Ricky 和 RealDan 轮流抓娃娃。
Ricky 每轮只能从其中一个娃娃机中抓走偶数个娃娃。
RealDan 每轮只能从其中一个娃娃机中抓走奇数个娃娃。
每人每轮至少抓走一个娃娃(他们都超级厉害),Ricky 先开始抓。
他们在神秘人的教导下,都已经变得非常聪明。最后谁抓不了娃娃,谁就被视为 loser,并且还要把自己抓到的娃娃送给对方,loser也必须去Winner喜欢的地方吃饭。
现在他们找到你,想让你看一下他们究竟谁可以赢。
Note: All the best wishes give Ricky and RealDan by their old friend ~

输入描述:

第一行一个t,表示t组数据。
每组数据有两行:
第一行一个n(1 <= n <= 100000)代表n个娃娃机
下一行有n个数字,代表每一个娃娃机中的娃娃数量a[i] (1 <=  a[i] <= 1e9)

输出描述:

如果最后Ricky获胜,则输出“Ricky is Winner”(不包括双引号),反之则输出“RealDan is Winner”(不包括双引号)。

输入

1
2
1 2

输出

RealDan is Winner

备注:

If you are so boring, you can play it ~
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
    cout << endl;
    cout << "                          Good luck ~" << endl;
    for (double y = 1.5; y > -1.5; y -= 0.1)
    {
        for (double x = -1.5; x < 1.5; x += 0.05)
        {
            double a = x * x + y * y - 1;
            if ((a * a * a - x * x * y * y * y) <= 0)
                cout << '*';
            else cout << " ";
        }
        cout << endl;
    }
    return 0;
}

解题思路

简单的博弈题,因为Ricky每轮只能从其中一个娃娃机中抓走偶数个娃娃,而RealDan每轮只能从其中一个娃娃机中抓走奇数个娃娃。故只要Ricky抓过之后,RealDan都可以把偶数变成奇数,故到最后一定是RealDan赢,除非是只有一堆并且还是偶数堆,Ricky才会赢。

#include <iostream>
using namespace std;
int main()
{
    int t, n, a;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d", &a);
        if (n == 1 && a % 2 == 0)
            printf("Ricky is Winner\n");
        else printf("RealDan is Winner\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lzyws739307453/article/details/85474924