HDU 4764-Stone(博弈)
来源:互联网 发布:成都软件学院 编辑:程序博客网 时间:2024/05/01 05:32
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 130 310 20 0
Sample Output
JiangTangJiang
题意:
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;}
0 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 【巴什博弈】
- HDU 4387 Stone Game 博弈
- 【HDOJ 4764】 Stone (博弈)
- HDU 4764 Stone(巴什博弈变形)
- HDU 4764(Stone) 巴什博弈变形 Java
- hdu 1729 Stone Game 【博弈-找规律】
- HDU 4388 Stone Game II(博弈)
- HDU 4764 Stone (简单博弈) 2013 ACM/ICPC 长春网络赛
- 测试
- OgreRoot
- 跟着8张思维导图学习javascript
- 浅析Comet技术在Java Web实时系统开发中的应用
- 减去试块在main
- HDU 4764-Stone(博弈)
- 非预期的例外
- SUSE下安装openssl
- 异常说明符
- chrome插件 postman插件 接口测试、API & HTTP 请求调试工具
- Python 多级排序
- 储存webview 的 cookie
- jQuery中的Each
- void类型及void指针