博弈论基础

hdu 1846

```

十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫《勇敢者的游戏》(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻。 
今天,大家选择上机考试,就是一种勇敢(brave)的选择;这个短学期,我们讲的是博弈(game)专题;所以,大家现在玩的也是“勇敢者的游戏”,这也是我命名这个题目的原因。 
当然,除了“勇敢”,我还希望看到“诚信”,无论考试成绩如何,希望看到的都是一个真实的结果,我也相信大家一定能做到的~ 

各位勇敢者要玩的第一个游戏是什么呢?很简单,它是这样定义的: 
1、  本游戏是一个二人游戏; 
2、  有一堆石子一共有n个; 
3、  两人轮流进行; 
4、  每走一步可以取走1…m个石子; 
5、  最先取光石子的一方为胜; 

如果游戏的双方使用的都是最优策略,请输出哪个人能赢。 
Input
输入数据首先包含一个正整数C(C<=100),表示有C组测试数据。 
每组测试数据占一行,包含两个整数n和m(1<=n,m<=1000),n和m的含义见题目描述。 
Output
如果先走的人能赢,请输出“first”,否则请输出“second”,每个实例的输出占一行。
Sample Input
2
23 2
4 3
Sample Output
first
second

```

#include<stdio.h>
#include<string.h>
int T,n,m,t[1010];
int main() {
	scanf("%d",&T);
	while(T--) {
		scanf("%d%d",&n,&m);
		memset(t,0,sizeof t);
		for(int i=1;i<=n;i++) {
			for(int j=i-1;j>=i-m&&j>=0;j--) {
				if(!t[j]) {
					t[i]=1; break;
				}
			}
		}
		puts(t[n]?"first":"second");		
	}
}


hdu 1847

大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此。当然,作为在考场浸润了十几载的当代大学生,Kiki和Cici更懂得考前的放松,所谓“张弛有道”就是这个意思。这不,Kiki和Cici在每天晚上休息之前都要玩一会儿扑克牌以放松神经。 
“升级”?“双扣”?“红五”?还是“斗地主”? 
当然都不是!那多俗啊~ 
作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这样的: 
1、  总共n张牌; 
2、  双方轮流抓牌; 
3、  每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…) 
4、  抓完牌,胜负结果也出来了:最后抓完牌的人为胜者; 
假设Kiki和Cici都是足够聪明(其实不用假设,哪有不聪明的学生~),并且每次都是Kiki先抓牌,请问谁能赢呢? 
当然,打牌无论谁赢都问题不大,重要的是马上到来的CET-4能有好的状态。 

Good luck in CET-4 everybody! 
Input
输入数据包含多个测试用例,每个测试用例占一行,包含一个整数n(1<=n<=1000)。
Output
如果Kiki能赢的话,请输出“Kiki”,否则请输出“Cici”,每个实例的输出占一行。 
Sample Input
1
3
Sample Output
Kiki
Cici


#include<stdio.h>
int n,a[1010];
int main() {
	for(int i=1;i<=1000;i++) {
		for(int j=1;j<=i;j*=2) {
			if(a[i-j]==0) {
				a[i]=1; break;
			}
		}
	}
	while(scanf("%d",&n)!=EOF) {
		puts(a[n]?"Kiki":"Cici");
	}
}


poj 2975


Nim is a 2-player game featuring several piles of stones. Players alternate turns, and on his/her turn, a player’s move consists of removing one or more stones from any single pile. Play ends when all the stones have been removed, at which point the last player to have moved is declared the winner. Given a position in Nim, your task is to determine how many winning moves there are in that position.

A position in Nim is called “losing” if the first player to move from that position would lose if both sides played perfectly. A “winning move,” then, is a move that leaves the game in a losing position. There is a famous theorem that classifies all losing positions. Suppose a Nim position contains n piles having k1k2, …, kn stones respectively; in such a position, there are k1 + k2 + … + knpossible moves. We write each ki in binary (base 2). Then, the Nim position is losing if and only if, among all the ki’s, there are an even number of 1’s in each digit position. In other words, the Nim position is losing if and only if the xor of the ki’s is 0.

Consider the position with three piles given by k1 = 7, k2 = 11, and k3 = 13. In binary, these values are as follows:

 111
1011
1101
 

There are an odd number of 1’s among the rightmost digits, so this position is not losing. However, suppose k3 were changed to be 12. Then, there would be exactly two 1’s in each digit position, and thus, the Nim position would become losing. Since a winning move is any move that leaves the game in a losing position, it follows that removing one stone from the third pile is a winning move when k1 = 7, k2 = 11, and k3 = 13. In fact, there are exactly three winning moves from this position: namely removing one stone from any of the three piles.

Input

The input test file will contain multiple test cases, each of which begins with a line indicating the number of piles, 1 ≤ n ≤ 1000. On the next line, there are n positive integers, 1 ≤ ki ≤ 1, 000, 000, 000, indicating the number of stones in each pile. The end-of-file is marked by a test case with n = 0 and should not be processed.

Output

For each test case, write a single line with an integer indicating the number of winning moves from the given Nim position.

Sample Input
3
7 11 13
2
1000000000 1000000000
0
Sample Output
3
0


#include<stdio.h>
int n,a[1001];
int main() {
	while(scanf("%d",&n)&&n){
		int x=0,r=0;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]),x^=a[i];
		for(int i=1;i<=n;i++)if(a[i]>(a[i]^x))r++;
		printf("%d\n",r);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值