HDU 2188 mourns the victims of the 512 Wenchuan earthquake-selecting volunteers (Bashi game theory) and hdu2188

Source: Internet
Author: User

HDU 2188 mourns the victims of the 512 Wenchuan earthquake-selecting volunteers (Bashi game theory) and hdu2188

Address: HDU 2188

Bare Bashi game model.

When n = m + 1, since a maximum of m items can be taken at a time, no matter how many items are taken by the first accessor, the latter can take the remaining items at a time, and the latter wins, therefore, when the correct situation is n % (m + 1) = 0, it is facing a defeat. So when n = (m + 1) * r + s, (r is any natural number, s ≤ m), if the first accessor wants to take s items, if the latter takes x (≤ m), then the first takes m + 1-K, the result is (m + 1) (r-1, in the future, the winner will surely win. In short, we need to leave a multiple (m + 1) to the opponent to win.

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int main(){    int t, n, m;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        if(n%(m+1)==0)            puts("Rabbit");        else            puts("Grass");    }    return 0;}



Mourning for the victims of the 512 Wenchuan earthquake-selecting volunteers

Assuming that the conditions remain unchanged, I decided that Lin was added to the final list.

Hangdian acm2188

Change n % (m + 1) to this

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.