Be the Winner
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1656 Accepted Submission(s): 885
Problem Description
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
Input
You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases.
Output
If a winning strategies can be found, print a single line with "Yes", otherwise print "No".
Sample Input
2 2 2 1 3
Sample Output
No Yes
Source
与上一题一样。
代码:
/* ***********************************************
Author :xianxingwuguan
Created Time :2014-2-8 0:11:46
File Name :1.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
int a[10000];
int main(){
int T,i,j,k,m,n;
while(cin>>n){
int sum=0;
for(i=1;i<=n;i++)
cin>>a[i],
sum+=a[i]==1;
if(sum==n){
if(n%2==0)puts("Yes");
else puts("No");
}
else {
int flag=0;
for(i=1;i<=n;i++)
flag^=a[i];
if(flag)puts("Yes");
else puts("No");
}
}
return 0;
}