# P1288 Game II, p1288 Game ii

Source: Internet
Author: User

P1288 Game II, p1288 Game ii
Description

There is a number-taking game. Initially, a ring is given, and each side of the ring has a non-negative integer. At least one of these integers is 0. Then, place a coin on a node on the ring. The two players start the game starting from the coin node. The two players take turns to take the number. The rules for getting the number are as follows:

(1) Select an edge on the left or right of the coin, and the number of sides is not 0;

(2) reduce the number on the edge to any non-negative integer (at least to reduce );

(3) Move the coin to the other end of the edge.

If it is a player's turn, then the number on both sides of the coin is 0, then the player will lose.

For example, it describes the confrontation process between Alice and Bob. The black node indicates the node where the coin is located. Result figure (d) shows that when it is Bob's turn, the sides of the coin are 0, so Alcie wins.

(A) Alice (B) Bob (c) Alice (d) Bob

Now, your task is to determine whether the leader has a winning strategy based on the given ring, the value on the edge, and the starting point (where the coin is located.

Input/Output Format

Input Format:

The first line is an integer N (N ≤ 20), indicating the number of nodes in the ring.

The number of N in the second row, which must not exceed 30, indicates the number of N edge values in turn. The start position of the coin is on the node between the first side and the last side.

Output Format:

Only one line. If a winning policy exists, "YES" is output; otherwise, "NO" is output ".

Input and Output sample input sample #1:
`[Input 1] 42 5 3 0 [input 2] 30 0 0`
Output sample #1:
`[Output 1] YES [Output 2] NOYou can read the question with a blind face. ,`

This is a mathematical problem...

Let's take an example: there is an edge R pointing from x to y, its value is greater than 0, AB logarithm, now A goes

If the value is 1, A goes over, and the value changes to 0, B cannot return.

If the value is 2, A goes over and the value changes to 1. If B comes back, A will not die? We think they are all smart. How can they do this? (Assume that the first side has been completed, and the value is 0)

If the value is greater than 3 (we suppose it is 3), A goes over and the value changes to 2. If B comes back with kindness and the value changes to 1, it will not waste A step?

B. If I come back cruelly with the best action according to the meaning of the question and retrieve all the values, then the value will be 0, and this road will be blocked. A has done A meaningless thing, it also blocks A path that you can take, which is not good for first-hand,

Both methods obviously violate the optimal premise of both parties.

[/Color] [B] So we can know that, whether it is A or B, that is, whether it is A first hand or A later hand, every walk through A road must be completed, this makes the problem simple [/B].

Because there is at least 0, it is simpler .. Whoever pushes the opponent to a dead end (both sides are 0) will win

Start from the start point and start from both sides. If the distance between one side and the zero side is odd, the first hand wins.

` 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #define lli long long int 7 const int MAXN=2333;  8 int n,s[MAXN]; 9 int judge(int p)10 {11     return p&1;12 }13 void read(int &n)14 {15     char c='+';int x=0;bool flag=0;16     while(c<'0'||c>'9')17     {c=getchar();if(c=='-')flag=1;}18     while(c>='0'&&c<='9')19     {x=x*10+(c-48);c=getchar();}20     flag==1?n=-x:n=x;21 }22 int main()23 {24     read(n);25     for (int i=1;i<=n;i++) 26     read(s[i]);27     int a=0;28     while(s[++a]);29     int b=0;30     while(s[n+1-(++b)]);31     if (judge(--a)||judge(--b))  32     printf("YES");  33     else printf("NO");34 }`

Related Keywords:
Related Article

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.