Question Link
Question: there is a numberp=1
, A and B take turns, and P can be multiplied by 2 ~ each time ~ A number in 9, givenn
After one person operatesp>=n
Then the man wins and asks if the first hand wins.
- Winning status: there is a way to go to a losing status.
- Failed status: the successor status is a winning status.
We can know>=n
The numbers are all failed and can be transferred>=n
The smallest numbern/9
(Rounded up), son/9
~n-1
All are competitive. Likewisen/9/2
(All are rounded up) must be transferred to the smallestn/9
~n-1
(Must win) status, son/9/2
~n/9-1
To be defeated, so we can push it like this1
, Take a look1
Whether it is a winning or a defeated output.
PS.a/b
(Rounded up) can be written(a-1)/b+1
(Division ). Easy operation.
#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
[Original blog] poj 2505 a multiplication game combination game