1. 程式人生 > >牛客網 - Ricky’s RealDan’s Ricky(博弈)

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

題目連結: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;
}