# The 14th session of Zhejiang University of Finance and Economics Program Design competition D disport with Jelly NIM __algorithm

Source: Internet
Author: User

Source: Niu Ke Net

Time limit: c/s + + 1 seconds, other languages 2 seconds
Space restrictions: C/C + + 262144K, other languages 524288K
64bit IO Format:%lld
Topic description
There is a game consisted of two players Alice and Bob, and one referee Jelly.

At the, Jelly'll choose a special integer X and write down on the paper, but Don t show it to each player. Then Jelly would 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. The the 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 would announce one of three results:
1. "Lose". That's means K is equal to X and this player loses the game.
2. "Large". That's means K is larger than X, and the other one should guess the integer from L to k−1 inclusively in the next. (R becomes k−1)
3. "Small." That's means K is smaller than X, and the 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 would show players the paper and X so as to prevent the Jelly.

One day, Alice and Bob play this game again. But they reach a consensus this loser needs to pay for the winner ' s cart. Cause neither of them wants to lose the game, they order braised chicken and Rice (Huangmenji) for Jelly in different times . In return, Jelly tells Alice and Bob the special integer X secretly. So, both players would use the best strategy to play the game.

Now, the question are who would win the game under this situation. (Alice goes-a)

Enter a description:
The 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.

Output Description:
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.
Example 1
Input
2
1 1 1
1 2 2
Output
Case #1: Bob
Case #2: Alice
Note:
For the "a", Alice can only guess the "integer 1", so she loses the game and 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 Game

``` #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; }
```
Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## 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.