【POJ1740】A New Stone Game 构造博弈

题意:多组数据,每组数据一个先n,然后给出n堆石子的数目。

两人轮流操作,每次可以从某数量为xi的石子堆中扔掉k个石子(k∈[1,xi]),然后剩余xi-k个,可以把g个石子随意分给其他堆(不能凭空建堆出来,g∈(0,xi-k))。

题解:

首先构造平衡状态:

有偶数堆,且可以两两配对。

这样可以理解为先手玩一下,后手可以有同样的应对策略。(脑洞开一下就好了,这不是难点少年)

那么如何构造平衡状态呢?

考虑如果总数是奇数,那么有下图。

然后如果总数是偶数,那么有下两图。

图一为我们先将石子排序,然后最高的放到左边

图二就是配对方式。(到这其实就很水了)

但是如果刚开始就是平衡的那就没招了,先手只能输了。

呃,只能说可以发现

好了,可以看代码了:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 15
using namespace std;
int stone[N],n;
int main()
{
//	freopen("test.in","r",stdin);
	int i,j,k;
	while(scanf("%d",&n),n)
	{
		for(i=1;i<=n;i++)scanf("%d",&stone[i]);
		if(n&1)puts("1");
		else {
			sort(stone+1,stone+n+1);
			bool flag=1;
			for(i=1;i<n;i+=2)flag&=(stone[i]==stone[i+1]);
			if(flag)puts("0");
			else puts("1");
		}
	}
	return 0;
}
时间: 2024-10-10 18:21:54

【POJ1740】A New Stone Game 构造博弈的相关文章

poj1740 A New Stone Game(博弈)

A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5028   Accepted: 2753 Description Alice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob

POJ1740|A NEW STONE GAME|博弈论

DescriptionAlice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob move the stones in turn.At each step of the game,the player choose a pile,remove at least one stones

URAL 1180. Stone Game (博弈 + 规律)

1180. Stone Game Time limit: 1.0 second Memory limit: 64 MB Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition

HDU 5996:dingyeye loves stone(阶梯博弈)

http://acm.hdu.edu.cn/showproblem.php?pid=5996 题意:在一棵树上进行博弈,每次只能将当前的结点的石子放到父节点上,最后不能移动的输. 思路:比赛的时候想的是对于每一个深度为dep的结点,可以转化为dep堆同样的深度为1的结点,然后就不会了,忘了最后异或起来偶数可以抵消,相当于对方移动,我方也跟着移动对方上一个回合移动的石子,所以最后只要考虑深度为奇数的结点. 1 #include <cstdio> 2 #include <algorithm&

【UVA1378】A Funny Stone Game (博弈-求SG值-输出方案)

[题目] Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2, ..., n − 1. Twopersons pick stones in turn. In every turn, each person selects three piles of stones numbered i, j, k(i < j, j ≤ k and at least one s

HDU 4388 Stone Game II {博弈||找规律}

Stone Game II Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 531    Accepted Submission(s): 300 Problem Description Stone Game II comes. It needs two players to play this game. There are some p

POJ 1740 A New Stone Game(博弈)题解

题意:有n个石子堆,每一个都可以轮流做如下操作:选一个石堆,移除至少1个石子,然后可以把这堆石子随便拿几次,随便放到任意的其他石子数不为0的石子堆,也可以不拿.不能操作败. 思路:我们先来证明,如果某个石子数有偶数堆,则先手必败,因为无论先手怎么做,后手都能模仿先手,最后把石子取光.显然全是偶数堆是必败态.如果有奇数堆怎么办?我们就把最大的奇数堆取光,然后把其他奇数堆变成偶数堆.但是一定能保证可以吗?答案是可以.假设奇数堆的石子数为 x1,x2,x3...xn,那么我们分别给每一堆加上x2-x1

HDU5973 Game of Geting Stone(威佐夫博弈)

Two people face two piles of stones and make a game. They take turns to take stones. As game rules, there are two different methods of taking stones: One scheme is that you can take any number of stones in any one pile while the alternative is to tak

POJ 1740 A New Stone Game(博弈)

A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6586 Accepted: 3611 Description Alice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob mov