Hdu3951coin game (symmetric game)

Source: Internet
Author: User
Coin game

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2947 accepted submission (s): 1609


Problem descriptionafter HH has learned how to play Nim game, he begins to try another coin game which seems much easier.

The game goes like this:
Two players start the game with a circle of n coins.
They take coins from the circle in turn and every time they cocould take 1 ~ K continuous coins.
(Imagining that ten coins numbered from 1 to 10 and K equal to 3, since 1 and 10 are continuous, you cocould take away the continuous 10, 1, 2, but if 2 was taken away, you couldn't take 1, 3, 4, because 1 and 3 aren't continuous)
The player who takes the last coin wins the game.
Suppose that those two players always take the best moves and never make mistakes.
Your job is to find out who will definitely win the game.

 

Inputthe first line is a number t (1 <= T <= 100), represents the number of case. The next t blocks follow each indicates a case.
Each case contains two integers n (3 <= n <= average, 1 <= k <= 10 ).

 

Outputfor each case, output the number of case and the winner "first" or "second". (as shown in the sample output)

 

Sample input23 13 2

 

Sample outputcase 1: firstcase 2: Second

The coin is enclosed in a circle numbered 1-N. Each person can take a maximum of K consecutive coins each time, give N and K, and ask who wins.

Question: In a typical symmetric game, when k = 1, it depends on the parity of n. When k> = 2, the symmetric game is applied: after the first hand is obtained, the ring becomes a chain, as long as a symmetric situation is created, the latter can win and divide the chain into equal chains.

K> = 2, The Houyi will surely be able to create a symmetric situation. At this time, the Houyi will win

 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() { 4     int t; 5     while(~scanf("%d",&t)) 6     { 7          8         for(int i=1;i<=t;i++) 9         {10             int n,k;11             scanf("%d %d",&n,&k);12             if(k>=n)13             {14                 printf("Case %d: first\n",i);15             }else16             {17                 if(k==1)18                 {19                     if(n%2==0)printf("Case %d: second\n",i);20                     else printf("Case %d: first\n",i);21                 }else22                 {23                     printf("Case %d: first\n",i);24                 }25             }26         }27     }28     return 0;29 }

 

Hdu3951coin game (symmetric game)

Contact Us

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.