2699: 16 and 18
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| | 1s | 65536K | 285 | 65 | Standard |
16 and 18 are good friends. They are playing a game.
The rules are as following:
(1) 16 and 18 will give numbers in turn. At first 16, then 18, and then 16...
(2) If the previous one give a number A, the number the next one gives, namely B, must satisfy that
1 <= B - A <= k.
(3) Who first gives the number larger than or equal to N will lose the game.
(4) The game always starts with 16, and he can only give a number from [1, k] in the first round.
(5) Suppose that both of them will try their best to win.
Input
In each line, there will be two integers N (0 < N <= 100, 000, 000) and k (0 < k <= 100). Input terminates when N = k = 0
Output
For each case, print the winner's name in each line.
Sample Input
1 1 30 3 10 2 0 0
Sample Output
18 16 18
Problem Source: homeboy
博弈问题详细情况可以看我转载的博弈问题总结
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k),n&&k)
{
if((n-1)%(k+1)==0)cout<<18<<endl;
else cout<<16<<endl;
}
return 0;
}
本文介绍了一个关于两个玩家轮流给出数字的游戏,通过设定的规则来判断最终赢家的算法实现。输入包括目标数字N和每轮可增加的最大值k,输出为胜利者的名字。
878

被折叠的 条评论
为什么被折叠?



