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

 

Source

2013 ACM/ICPC Asia Regional Changchun Online

题目大意:对于两个人,轮流在白板上写数字,每人写的数字y要与上一个人写的数字x满足 1<=y-x<=k  的关系;

一开始输入n和k,Tang先写,Jiang后写,谁先写的数字大于等于n,谁输;

输出赢的那个人的名字;

巴什博弈,因为是谁先输出一个大于等于n的数字谁就输了,转换成谁先输出等于n-1的数字谁就赢了(这是必然的)

那么根据巴什博弈的结果,如果满足(n-1)=(k+1)*m,那么后手必定能写到n-1,那么后手必定赢,反之若(n-1)=(k+1)*m+c的话,先手必定赢;

因此直接输出结果即可:

ac:

#include<stdio.h>
#include<string.h> 
#include<math.h> 
   
#include<map>  
//#include<set>
#include<deque> 
#include<queue> 
#include<stack> 
#include<bitset>
#include<string> 
#include<fstream>
#include<iostream> 
#include<algorithm> 
using namespace std; 
 
#define ll long long 
#define INF 0x3f3f3f3f 
//#define mod 1e9+7
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// 水印
//std::ios::sync_with_stdio(false);

int main()
{
	std::ios::sync_with_stdio(false);
    int n,k;
    while(cin>>n>>k&&n)
    {
    	if((n-1)%(k+1))
    		cout<<"Tang"<<endl;
    	else
    		cout<<"Jiang"<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/qq_40482358/article/details/82252054