您的位置:首页 > 其它

[原博客] POJ 2505 A multiplication game 组合游戏

2014-09-07 23:47 239 查看
题目链接
题意: 有一个数
p=1
,甲乙两人轮流操作,每次可以把p乘2~9中的一个数,给定一个
n
,当一个人操作后
p>=n
,那么这个人赢,问先手是否必胜。

必胜状态:存在一种走法走到一个必败状态。

必败状态:后继状态都为必胜状态。

我们可以知道
>=n
的数都为必败状态,可以转移到
>=n
的最小的数为
n/9
(上取整),所以
n/9
~
n-1
都为必胜态,同理
n/9/2
(都为上取整)为最小的必须转移到
n/9
~
n-1
(必胜状态)的状态,所以
n/9/2
~
n/9-1
为必败态,于是就可以这样推到
1
,看一下
1
是必胜态还是必败态输出即可。

ps.
a/b
(上取整)可以写为
(a-1)/b+1
(整除)。方便运算。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

//by zrt
//problem:
using namespace std;
typedef long long LL;
const int inf(0x3f3f3f3f);
const double eps(1e-9);

int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
LL n;
while(~scanf("%lld",&n)){
bool ok;
while(1){
LL p=(n-1)/9+1;
if(1>=p){
ok=1;break;
}else n=p;
p=(n-1)/2+1;
if(1>=p){
ok=0;break;
}else n=p;
}
if(ok){
puts("Stan wins.");
}else{
puts("Ollie wins. ");
}
}

return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: