Hdoj 2509 Be the Winner

Diciption

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).

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

anti_nim游戏。这种Nim是不能操作者赢。Sg函数的话还是和普通的Nim一样,初始化是sg[0]=0;最后游戏的和的话,先手必胜当且仅当:    1.每一堆石子都是1并且Nim和为0.    2.有至少一堆石子>1并且Nim和不为0.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int sg[105],n,m;
int now,v[1005];

inline void init(){
	sg[0]=0;
	for(int i=1;i<=100;i++){
		now=0;
		for(int j=0;j<i;j++)
		    for(int k=j;k+j<i;k++) v[sg[j]^sg[k]]=i;
		while(v[now]==i) now++;

		sg[i]=now;
	}
}

int main(){
	init();

	while(scanf("%d",&n)==1){
		bool flag=0;
		int a,ans=0;

		while(n--){
			scanf("%d",&a);
			ans^=sg[a];
			if(a>1) flag=1;
		}

		if((!flag&&!ans)||(flag&&ans)) puts("Yes");
		else puts("No");
	}

	return 0;
}

  

 

原文地址:https://www.cnblogs.com/JYYHH/p/8508930.html

时间: 2024-08-07 04:27:47

Hdoj 2509 Be the Winner的相关文章

hdu 2509 Be the Winner

详解:hdu 1907 John - lihaogegehuting的专栏 - 博客频道 - CSDN.NET 两道题几乎一样 代码如下: #include<stdio.h> int main() { int T,a[100],i,sum,ok; while(~scanf("%d",&T)) { sum=0; ok=0; for(i=1;i<=T;i++) { scanf("%d",&a[i]); if(a[i]>1) ok=

HDU 2509 Be the Winner(取火柴博弈2)

传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n; while(~scanf("%d",&n)) { int a,res=0; int c=0,g=0; for(int i=0;i<n;i++) { scanf("%d",&a); if(a>=2) c++;

博弈题目小结

HDU 2174 kiki's game 题意:有一个N*M的棋盘,起点在右上角,两个人每轮可把棋子向左.向下或者向左下移动一格,直到不能移动棋子者输. NP图解决: 概念: 必败点(P点):前一个选手将取胜的位置称为必败点. 必胜点(N点):下一个选手将取胜的位置成为必胜点. 性质: 步骤: NP图: AC code: 1 #include <bits/stdc++.h> 2 #define inc(i, j, k) for(int i = j; i <= k; i++) 3 #def

HDOJ 4974 A simple water problem

A simple water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 173    Accepted Submission(s): 112 Problem Description Dragon is watching competitions on TV. Every competition is held be

hdoj 1052 Tian Ji -- The Horse Racing【田忌赛马】 【贪心】

思路:先按从小到大排序, 然后从最快的開始比(如果i, j 是最慢的一端, flag1, flag2是最快的一端 ),田的最快的大于king的 则比較,如果等于然后推断,有三种情况: 一:大于则比較,二等于在推断田的最慢的是不是比king的最快的慢,三小于则与king的最快的比較: Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe

HDOJ 4972 A simple dynamic programming problem

找规律...数据可能不合法...输出0 A simple dynamic programming problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 85    Accepted Submission(s): 31 Problem Description Dragon is watching NBA. He loves Ja

【HDOJ 4764】 Stone (博弈)

[HDOJ 4764] Stone (博弈) Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1090    Accepted Submission(s): 761 Problem Description Tang and Jiang are good friends. To decide whose treat it is

ACM--田忌赛马--贪心--HDOJ 1052--Tian Ji -- The Horse Racing

HDOJ题目地址:传送门 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25520    Accepted Submission(s): 7506 Problem Description Here is a famous story in Chinese history. "Th

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>