HDU1846 Bashbor Game

Source: Internet
Author: User

Ba Shi game:

A person to take 1~m, then who face m+1 situation of the time will be defeated. Suppose n=k* (m+1) +s, (k for any, s<m+1), then I (the initiator) First Take that s, and then let another person take, from now on, as long as I take the number with the number of the previous person and equal to m+1, so after the inevitable face will be defeated situation, That is, when the last one is finished, it must be T (t<m) to me, that is, I win. such as 2,23= (3x7) +2; that I first took off 2, and no matter how much I can make this round a total of 3, and then he will face 3 this situation, and then I will win, then when will be defeated, it is obvious if I face is (m+1) multiples of the situation will be defeated. That is, we only need to determine whether n% (m+1) equals 0 to know who wins who is negative.
1#include <cstdio>2 intMain ()3 {4     intt, N, M;5scanf"%d", &t);6      while(t--){7scanf"%d%d", &n, &m);8         if(N <=m)9printf"first\n");Ten         Else if(n% (M +1) ==0) Oneprintf"second\n"); A         Else -printf"first\n"); -     } the     return 0; -}

HDU1846 Bashbor 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.