HDU 3951 (game) Coin game

Source: Internet
Author: User

Consider two simple cases first:

    • If the initiator can finish the coin once, that is K >= N, then the initiator wins
    • If you can only take one coin at a time, that is, k = 1, then if there is an odd number of coins to win, if there is an even number of coins to win.

The rest of the situation is that the initiator can not finish it once, and each time you may take one or two coins.

The rest of the coin will become a chain, if the hand can finish the best, can not be finished, take one or two coins so that the chain into two equal length.

It must be able to do that.

Because if the chain has an odd number of coins, then take the middle one;

If you have an even number of coins, take the middle two.

After becoming equal to the two strands, the initiator takes the number of coins in which chain, and the other one in the other chain, until all the coins are taken.

So the flip-win.

1#include <cstdio>2 3 intMain ()4 {5     //freopen ("In.txt", "R", stdin);6 7     intT scanf"%d", &T);8      for(intKase =1; Kase <= T; kase++)9     {Ten         intN, K; Onescanf"%d%d", &n, &k); Aprintf"Case %d:", Kase); -         BOOLFirst ; -         if(k = =1) First = N &1?true:false; the         Else if(k >= n) First =true; -         ElseFirst =false; -printf"%s\n", first?" First":"Second"); -     } +  -     return 0; +}
code June

HDU 3951 (game) Coin 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.