(Game SG function Primer) Brave game--hdu--1846

Source: Internet
Author: User

Link:

http://acm.hdu.edu.cn/showproblem.php?pid=1846

First of all to play a game, citing Hangzhou Electric Courseware:

(1) Players: 2 people;
(2) Props: 23 cards;
(3) Rules:
The game both sides take turns to draw cards;
Each person is limited to 1, 2 or 3 cards at a time;
Poker takes light, then the game is over;
The one who wins the final card is the winner.

Think about it.

First of all, the discussion of the game is discussed in the best case we all play. (If 2 players have a different IQ, there is no discussion. )

Introduction Concept: P point is a must lose point, a player is located at this point, as long as the other side without errors, will be defeated;

N Point is to win points, a player located at this point, as long as their own no mistakes, then win.

Theorem:

First, all the endpoints are a must defeat P (on the game, the turn who took the card, there are 0 cards left, the person loses, because no card is preferable);

Second, all one step can go to the point P is N point;

Third, through one-step operation only to N point is P point;

Draw your own look.

X:0 1 2 3 4 5 6 7 8 9 10 ...

Pos:p N-n n p n n n p n n ...

So if player A is at N point. As long as each time the P point to each other, then a win;

Conversely, if player A is located at p Point, he can only go to n points at a time, and as long as B each time the P point to a, a will be defeated;

Here is a good understanding of the next;

If the above is understood. Please solve the following topic: HDU 1846 2147 (attention to the topic limit memory) (first 2 practice practiced hand, do not make the words hint: to find the law)

Code:

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>using namespacestd;#defineN 1100intMain () {intT; scanf ("%d", &t);  while(t--)    {        intN, M; scanf ("%d%d", &n, &m); if(n% (m+1)==0) printf ("second\n"); Elseprintf"first\n"); }    return 0;}

(Game SG function Primer) Brave game--hdu--1846

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.