POJ2505 A multiplication game(博弈)
阿新 • • 發佈:2018-08-03
names fine eof 一個 fin sla sin 是否 long
題意
開始時$p = 1$,每次可以乘$2 - 9$,第一個使得$p \geqslant n$的人贏
問先手是否必勝
$1 <n <4294967295$
Sol
認真的推理一波。
若當前的數為$\frac{n}{9} \leqslant x \leqslant n$,則先手必勝
若當前的數為$\frac{n}{18} \leqslant x \leqslant \frac{n}{9}$,則先手必敗
若當前的數為$\frac{n}{18 * 9} \leqslant x \leqslant \frac{n}{18}$,則先手必勝
$\dots \dots \dots \dots \dots \dots \dots \dots \dots\dots\dots \dots $
然後就顯然了,每次除$18$,最後判一下就行了。
然而不知道為啥用double才能過qwq。。。
#include<cstdio> #define LL long long using namespace std; int main() { double n; while(scanf("%lf", &n) != EOF) { while(n > 18) n = n / 18; if(n <= 9) puts("Stan wins."); else puts("Ollie wins."); } return 0; }
POJ2505 A multiplication game(博弈)