HDU 4994 Revenge of Nim (博弈)

题目链接:HDU 4994 Revenge of Nim

题意:两个取石头,分别在N堆里去。只有第一堆取完才能取第二堆,以此类推,最后一个取完的为赢家。

思路:从头开始扫,直到第一个不为1为止,判断现在的主动权在谁手里,谁就是赢家。(这里读者可以自己写几组数据试试。)

AC代码:

#include<stdio.h>
#include<string.h>

int main()
{
	int yaoga;
	int t,i,n;
	int a[1010];

	while(scanf("%d",&t)!=EOF)
	{
		while(t--)
		{
			scanf("%d",&n);
			int count=0;
			bool ok=true;
			for(i=1;i<=n;i++)
			{
				scanf("%d",&a[i]);
				if(a[i]>1) ok=false;
				if(ok) count++;
			}
			if(ok)
			{
				if(count%2==0)
					printf("No\n");
				else
					printf("Yes\n");
			}
			else
			{
				if(count%2)
					printf("No\n");
				else
					printf("Yes\n");
			}
		}
	}
	return 0;
}
时间: 2024-12-13 15:46:44

HDU 4994 Revenge of Nim (博弈)的相关文章

hdu 4994 Revenge of Nim(博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 Problem Description Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remov

HDU - 4994 Revenge of Nim

Problem Description Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from

hdu 5088 Revenge of Nim II(高斯消元)

题目链接:hdu 5088 Revenge of Nim II 题目大意:Nim游戏的变形,因为游戏很不公平,所以现在转变规则,后手可以选取若干堆石子剔除,剩下堆的石子用 来进行游戏,问说后手可能胜利吗. 解题思路:其实即为取出非0堆石子,使得Nim和为0.因为是Nim和(亦或),所以以每个位建立方程,列出40个方 程,进行亦或形式的高斯消元,因为全0肯定为一解,所以方程肯定有解,那么存在多解的情况即为存在自有变元. #include <cstdio> #include <cstring

ACM学习历程—HDU 3915 Game(Nim博弈 &amp;&amp; xor高斯消元)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所有xor和为0. 那么自然变成了n个数里面取出一些数,使得xor和为0,求取法数. 首先由xor高斯消元得到一组向量基,但是这些向量基是无法表示0的. 所以要表示0,必须有若干0来表示,所以n-row就是消元结束后0的个数,那么2^(n-row)就是能组成0的种数. 对n==row特判一下. 代码:

hdu 5088 Revenge of Nim II(BestCoder Round #16)

Revenge of Nim II                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 203    Accepted Submission(s): 63 Problem Description Nim is a mathema

HDU 5011 Game(Nim博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5011 贴一发博弈的链接的链接:http://blog.csdn.net/u012860063/article/details/21816635 Problem Description Here is a game for two players. The rule of the game is described below: ● In the beginning of the game, ther

HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 79    Accepted Submission(s): 48 Problem Description Two players take turns picking candies from n heaps,the player who picks the las

hdu 5795 A Simple Nim 博弈sg函数

A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick an

hdu 1730 Northcott Game (nim博弈变形)

# include <algorithm> # include <stdio.h> # include <string.h> # include <math.h> # include <iostream> using namespace std; int main() { int n,m,i,a,b,cot; while(~scanf("%d%d",&n,&m)) { cot=0; for(i=0; i<