HDU 4764-Stone(博弈)
2014-09-12 13:03
162 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each case, print the winner's name in a single line.
[align=left]Sample Input[/align]
1 1
30 3
10 2
0 0
[align=left]Sample Output[/align]
Jiang
Tang
Jiang
题意:
J 和 T 轮流说数字,后一个数字Y 与前一个数字 X 应该符合 1<=Y - X <=k ; 谁说的数字大于等于 N , 则输, J 先。
思路:
简单的博弈题。采用逆推的想法,首先数到 N 和大于 N 的数就输,因为两人都很聪明,则一个数到N-1, 则另一个人就输了,则这个位置叫做必胜位。再往前推,如果有人走到了N-1-1 到 N-1-k 的位置,则另一个人肯定会在 N-1 的位置,则这个人就会输了。则这些个位置是必输点。
样例:N= 10,K= 2
0 1 2 3 4 5 6 7 8 9 10
Y N N Y N N Y N N Y N
可以发现0 位置就是J的比赛结果,必输必赢是周期为(k+1)的循环,所以可以取模。
CODE:
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each case, print the winner's name in a single line.
[align=left]Sample Input[/align]
1 1
30 3
10 2
0 0
[align=left]Sample Output[/align]
Jiang
Tang
Jiang
题意:
J 和 T 轮流说数字,后一个数字Y 与前一个数字 X 应该符合 1<=Y - X <=k ; 谁说的数字大于等于 N , 则输, J 先。
思路:
简单的博弈题。采用逆推的想法,首先数到 N 和大于 N 的数就输,因为两人都很聪明,则一个数到N-1, 则另一个人就输了,则这个位置叫做必胜位。再往前推,如果有人走到了N-1-1 到 N-1-k 的位置,则另一个人肯定会在 N-1 的位置,则这个人就会输了。则这些个位置是必输点。
样例:N= 10,K= 2
0 1 2 3 4 5 6 7 8 9 10
Y N N Y N N Y N N Y N
可以发现0 位置就是J的比赛结果,必输必赢是周期为(k+1)的循环,所以可以取模。
CODE:
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <string> #include <cstring> #include <queue> #include <stack> #include <vector> #include <set> #include <map> const int inf=0xfffffff; typedef long long ll; using namespace std; bool check(int n, int k) { return (n%(k+1) == 1); } int main() { int N,K; while(~scanf("%d %d", &N, &K),N){ if(check(N, K)) { printf("Jiang\n"); } else{ printf("Tang\n"); } } return 0; }
相关文章推荐
- HDU 4764 Stone (巴什博弈)
- HDU 4764 Stone (巴什博弈)
- HDU 4764 Stone(简单博弈)
- HDU 4764 Stone 巴什博弈
- HDU-4764-Stone 【巴什博弈】
- HDU 4764 Stone(博弈)
- hdu 4764 Stone(博弈)
- hdu 4764 Stone (巴什博弈,披着狼皮的羊,小样,以为换了身皮就不认识啦)
- hdu 4764(stone) 巴什博弈
- HDU 4764 Stone (巴什博弈)
- HDU 4764 Stone(巴什博弈变形)
- 2013长春网赛 1006 hdu 4764 Stone(巴什博弈)
- HDU 4764 Stone (巴什博弈变形)
- HDU 4764 Stone(博弈)
- [巴什博弈] HDU 2149 Public Sale & HDU 1847 Good Luck in CET-4 Everybody! & HDU 4764 Stone
- HDU 4764 Stone (2013长春网络赛,水博弈)
- HDU 4388 Stone Game II 博弈,规律题
- HDU 4764 Stone
- A simple stone game - HDU 2486 K倍递减博弈
- 【HDU 5996 dingyeye loves stone】+ 尼姆博弈