第十四屆浙江財經大學程式設計競賽 D Disport with Jelly NIM __Algorithm

來源:互聯網
上載者:User

連結:https://www.nowcoder.com/acm/contest/89/D
來源:牛客網

時間限制:C/C++ 1秒,其他語言2秒
空間限制:C/C++ 262144K,其他語言524288K
64bit IO Format: %lld
題目描述
There is a game consisted of two players Alice and Bob, and one referee Jelly.

At first, Jelly will choose a special integer X and write down on the paper, but don’t show it to each player. Then Jelly will give players two integers L and R, which means X ranges from L to R inclusively. Alice and Bob start to guess the integer X in turns, and Alice goes first. The first one who guesses the integer X loses the game.

The specific rules of the game are as follows:
One player guesses an integer K (K ∈ [L, R]), and Jelly will announce one of three results:
1. “Lose”. That means K is equal to X, this player loses the game.
2. “Large”. That means K is larger than X , other one should guess the integer from L to K − 1 inclusively in the next. (R becomes K − 1)
3. “Small.” That means K is smaller than X, other one should guess the integer from K+1 to R inclusively in the next. (L becomes K + 1)

If one player loses the game, Jelly will show players the paper with X so as to prevent Jelly to cheat the players.

One day, Alice and Bob play this game again. But they reach a consensus that the loser needs to pay for the winner’s shopping cart. Cause neither of them wants to lose the game, they order Braised Chicken and Rice(HuangMenJi) for Jelly at different times. In return, Jelly tells Alice and Bob the special integer X secretly. So, both players will use the best strategy to play the game.

Now, the question is who will win the game under this situation. (Alice goes first)

輸入描述:
The first line contains an integer T, where T is the number of test cases. T test cases follow.
For each test case, the only line contains three integers L, R and X.
• 1 ≤ T ≤ 105.
• 1≤L≤X≤R≤105.

輸出描述:
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting
from 1) and y is the winner’s name.
樣本1
輸入
2
1 1 1
1 2 2
輸出
Case #1: Bob
Case #2: Alice
備忘:
For the first case, Alice can only guess the integer 1, so she loses the game, the winner is Bob.
For the second case, if Alice guesses the integer 1, then Bob can only guess the integer 2. So the winner
is Alice.

題意:NIM博弈

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include<map>#include<vector>using namespace std;int main(){    int T;    scanf("%d",&T);int cs=0;    while(T--){            cs++;        int L,R,X;        scanf("%d%d%d",&L,&R,&X);        L=X-L;        R=R-X;        printf("Case #%d: ",cs);        if(L==R)            printf("Bob\n");        else printf("Alice\n");    }    return 0;}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.