POJ 2505
Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p >= n.
因为每个人都是聪明的,所以如果当前的p乘以9之后还不能>=n,那么他将选择乘以2,选择其他的数都将是对方赢的概率增加。
故我们可以从给定的数n倒推回来,首先[(n+8)/9,n-1] 的区间是必胜的区间,然后[(n+8)/9/2,(n+8)/9-1]是必败区间,以此类推下去,记录经过多少次就可以达到起始状态。
根据奇偶性来判断输赢。
#include <iostream> using namespace std; int main() { __int64 p; while(scanf("%I64d",&p)) { int t=0; while(p!=1) { if(t%2==0) p=(p+8)/9; else p=(p+1)/2; t++; } puts(t%2?"Stan wins.":"Ollie wins."); } return 0; }