现在的位置: 首页 > 综合 > 正文

长春赛区网赛 F Stone

2013年09月22日 ⁄ 综合 ⁄ 共 2326字 ⁄ 字号 评论关闭
文章目录

题目

Stone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

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

题解

虽然简单的博弈,但实在是为难了我这种一直不写博弈的渣土,无奈,手算了半天终于写出了代码=。=

首先解释下题目意思,jiang和tang两个好基友玩一个数字游戏。给一个N,给一个k。N代表着上限,就是说两个人在游戏中都不能超过N;k代表着可选择度,根据题目意思,写数字的时候,新生成的数字Y必须在老数字X的一个范围中([1+X,k+X])。所以我们先从样例开始:

N=1,k=1:

游戏规定,tang先开始说数字,由于游戏规则要求数字必须大于等于1,所以tang只能报1这个数字。然而由于规则要求,谁先让自己的数字大于等于N,那就输了。因此,tang必输无疑,所以胜者是jiang。

N=30,k=3:

可能会比较绕嘴,但是希望大家能慢慢看:假设jiang自己要赢这场比赛,那么他必须逼着tang说出30这个数字。那么毫无疑问,jiang要抢先说出29,这样就能赢得比赛。然而从tang的角度考虑,tang不会傻到直接送对面一个胜利,所以他必须阻止jiang说出29,那么就不能说出26这个数字,否则jiang就有机会。接着按照这个思路走下去:

jiang要抢25,tang不能说出22。

jiang要抢21,tang不能说出18。

jiang要抢17,tang不能说出14。

jiang要抢13,tang不能说出10。

jiang要抢9,tang不能说出6。

jiang要抢5,tang不能说出2。

好,停!

规律,规律!看到了没?只要tang第一步不说2以上的数字,tang就赢了。

tang可以说“1”。

所以,tang赢了。

N=10,k=2:

还是刚才的思路:

假设jiang想赢得比赛:

jiang要抢9,tang不能说出7。

jiang要抢6,tang不能说出4。

jiang要抢3,tang不能说出1。

所以,tang不能说比1大的数字,tang输了,jiang赢了。

N,k

这样我们就看到了一个规律,详细的看代码吧。

代码示例

/****
	*@Polo-shen
	*
	*/
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

using namespace std;

#define DBG 0
#define ShowLine DBG && cout<<__LINE__<<">>| "
#define dout DBG && cout<<__LINE__<<">>| "
#define write(x) #x" = "<<(x)<<" "
#define awrite(array,num) #array"["<<num<<"]="<<array[num]<<" "

#ifndef min
#define min(x,y) ((x) < (y) ? (x) : (y))
#endif

#ifndef max
#define max(x,y) ((x) > (y) ? (x) : (y))
#endif

int main(){
    int N,k;
    while (cin>>N>>k && (N && k)){
        int sum=N-1;
        int tmp=sum%(k+1);
        if (tmp!=0){
            cout<<"Tang"<<endl;
        }
        else {
            cout<<"Jiang"<<endl;
        }
    }
    return 0;
}

抱歉!评论已关闭.