[Poj] 2234 matches game (Game Theory)

Source: Internet
Author: User

Http://poj.org/problem? Id = 2234

Game theory is really profound and profound orz

First, it is easy to analyze it carefully. When there is only one heap, the first hand wins. When the two heap and the same heap, the first hand wins, and the other hand wins.

Based on the knowledge of Game Theory (this paper, Zhang Yifei: a rational understanding from the perceptual knowledge-a process of analyzing the answers to a class of Combat Games)

The situation can be broken down and the results can be merged.

The situation is always first-handed

If the sub-situation is victory or defeat, then the situation is victory

If the sub-situation is defeat or victory, then the situation is victory

If the sub-situation is defeat or defeat, the situation is defeat.

When the sub-situation is victory or victory, the situation is uncertain.

These properties correspond to binary exclusive or operations.

We set the situation to S, and the defeat to # S = 0, and the victory to # s! = 0

Set binary A and B

When! = 0 & B = 0, a ^ B! = 0

When a = 0 & B! = 0, B ^! = 0

When a = 0 & B = 0, a ^ B = 0

When! = 0 & B! If it is set to 0, a ^ B may be set to 0! = 0

The function f (x) = # X represents the binary value of X.

Then we can merge the situation into the final situation based on the above calculation.

 

I am not familiar with it. I have to study it carefully tonight. It is too broad and profound. Orz

#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>using namespace std;#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << #x << " = " << x << endl#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const int max(const int &a, const int &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=30;int n;int main() {int ans;while(~scanf("%d", &n)) {ans=0;rep(i, n) ans^=getint();ans?(puts("Yes")):(puts("No"));}return 0;}

 

 

 

 

Description

Here is a simple game. in this game, there are several piles of matches and two players. the two player play in turn. in each turn, one can choose a pile and take away arbitrary number of matches from the pile (of course the number of matches, which is taken away, cannot be zero and cannot be larger than the number of matches in the chosen pile ). if after a player's turn, there is no match left, the player is the winner. suppose that the two players are all very clear. your job is to tell whether the player who plays first can win the game or not.

Input

The input consists of several lines, and in each line there is a test case. at the beginning of a line, there is an integer m (1 <= m <= 20), which is the number of piles. then comes M positive integers, which are not larger than 10000000. these M integers represent the number of matches in each pile.

Output

For each test case, output "yes" in a single line, if the player who play first will win, otherwise output "no ".

Sample Input

2 45 453 3 6 9

Sample output

NoYes

Source

Poj monthly, readchild

[Poj] 2234 matches game (Game Theory)

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.