HDU 1846 interesting and interesting

Source: Internet
Author: User

In addition to the interesting game problem, I can't think of anything to describe. In addition to the useful knowledge, I can also lie to the ignorant children ............)

This is also a classic saying. It is called the bash game in English. Well, it was probably another thought of by bash.

The so-called bash game is:There are only a bunch of N items, and the two take items in turn. Each time at least one item is taken, up to m items are taken. Finally, Whoever obtains the light item is the winner.

Assume that n = m + 1. It is obvious that no matter how many items the current player takes, it cannot deny the fate of the player to be defeated. Our goal is always to lead to defeat,

Assuming m + 1 <n <2 (m + 1), the current player only needs to obtain (N-(m + 1) from it, resulting in a point of defeat (m + 1 ); assuming 2 (m + 1) <n <3 (m + 1), the current player only needs to retrieve

(N-2 (m + 1) items, the remaining 2 (m + 1) items in the heap, no matter how many items the opponent next to (1 <= x <= m ), number of items remaining S, m + 1 <S <2 (m + 1), we can take the corresponding number

The quantity of items leaves m + 1 items in the heap, SO 2 (m + 1) is also a must-have point; so the number of items in the heap S = K (m + 1) (k = 1, 2, 3 ......) It is a point of failure.

Finally, it is concluded that in this game:

1. If M> = N, the first player will win

2. If n = K (m + 1) + x (k = 1, 2, 3 ......; X <= m), wins first

3. If n = K (m + 1), the latter wins

Then .............................. You know


 # include 
  
    using namespace STD; int main () {int cCase; CIN> cCase; while (cCase --) {int n, m; bool flag = true; CIN> N> m; If (M> = N) Flag = true; else if (N % (m + 1) Flag = true; elseflag = false; If (FLAG) cout <"first" 
   
  

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.