【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 for dinner, they are playing a game. Specifically, Tang and Jiang will alternatively write numbers (integers) on a white board. Tang writes first, then Jiang, then again Tang, etc... Moreover, assuming
that the number written in the previous round is X, the next person who plays should write a number Y such that 1 <= Y - X <= k. The person who writes a number no smaller than N first will lose the game. Note that in the first round, Tang can write a number
only within range [1, k] (both inclusive). You can assume that Tang and Jiang will always be playing optimally, as they are both very smart students.

Input

There are multiple test cases. For each test case, there will be one line of input having two integers N (0 < N <= 10^8) and k (0 < k <= 100). Input terminates when both N and k are zero.

Output

For each case, print the winner‘s name in a single line.

Sample Input

1 1
30 3
10 2
0 0

Sample Output

Jiang
Tang
Jiang

写数字游戏 轮流写出小于n的一个数 数字要求递增 并且当前玩家写出的数与前一玩家写的数差值 <= k  写出n的输

可以转换为取石子(然而题目就是Stone 为了不太赤果果 给改编了下= =也醉了

因此 只要(n-1)为(k+1)的倍数 即后手始终可以达到 k+1 2*(k+1) 3*(k+1)....的状态 这样先手必输 其余状态先手可达n-1

代码如下:

#include <bits/stdc++.h>

using namespace std;

int main()
{

	int n,m,t,i,j,u,v,w;
	while(~scanf("%d %d",&n,&m) && n+m)
	{
		if((n-1)%(m+1)) puts("Tang");
		else puts("Jiang");
	}

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-08 22:15:59

【HDOJ 4764】 Stone (博弈)的相关文章

题解报告:hdu 4764 Stone(巴什博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 Problem Description Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang and Jiang will alternatively write numbers (integers) on a wh

hdu 4763 stone(博弈)

F - Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4764 Description Tang and Jiang are good friends. To decide whose treat it is for dinner, they are playing a game. Specifically, Tang an

hdu 5996 dingyeye loves stone(博弈)

题目链接:hdu 5996 dingyeye loves stone 题意: 给你一棵树,树的每一个节点有a[i]个石子,每个人可以将这个节点的石子移向它的父亲,如果没有合法操作,那么就算输,现在给你当前的局面,问你能否赢 题解: 设根节点的深度为0,将所有深度为奇数的节点的石子数目xor起来,则先手必胜当且仅当这个xor和不为0. 证明同阶梯博弈.对于偶深度的点上的石子,若对手移动它们,则可模仿操作:对于奇深度上的石子,移动一次即进入偶深度的点. 时空复杂度O(n). 1 #include<b

hdoj 1729 Stone Games(SG函数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1729 看了题目感觉像Nim,但是有范围限制,有点不知道SG函数该怎么写 看了题解,最后才明白该怎么去理解 . 首先进行对s和c进行分类, 1.c = 0 的时候,无论怎样都填不满,直接跳过: 2.c = s 的时候,先手必败,即是P态: 3.c < s 的时候,可以分为两种情况: 1)c^2 + c < s 的时候,递归 2)c^2 + c > s 的时候,先手必胜,即N态 1 int me

博弈论基础——巴什博弈

->可以看这<- HDU.4764.Stone \(Description\) Tang,Jiang两人轮流写数,若A在写了X,则B只能写Y,满足1<=Y-X<=k.最先写数的T只能写[1,k]内的数.第一个写的数>=N的lose,问最后的winner. \(Solution\) 看做取N-1个石子,每次最多取K个,就是个巴什博弈了 #include <cstdio> int main() { int n,k; while(scanf("%d%d&quo

博弈知识整理

博弈知识整理 一.  巴什博奕(Bash Game): 只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个.最后取光者得胜. 显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜.因此我们发现了如何取胜的法则:如果n=(m+1)*r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果后取者拿走k (≤m)个,那么先取者再拿走m+1-k个,结果剩下(m+1)*(r-1)个,以后保持这样的取法,那

hdoj 2188 悼念512汶川大地震遇难同胞——选拔志愿者 【巴什博弈】

题意:... 策略:最简单的典型的巴什博弈. 代码: #include<stdio.h> int main() { int n, m; int t; scanf("%d", &t); while(t --){ scanf("%d%d", &n, &m); if(n%(m+1) == 0){ printf("Rabbit\n"); } else printf("Grass\n"); } } 题

hdoj 2147 kiki&#39;s game【博弈】

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 8041    Accepted Submission(s): 4781 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his m

HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

A simple stone game                                                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)