POJ 2505 A multiplication game(找规律博弈)

来源:互联网 发布:网上挂号什么软件 编辑:程序博客网 时间:2024/05/29 21:31

题目大意:给一个数N, 然后初始值给1,两个人轮流把这个数乘2-9的数,谁先达到这个数就必胜。问必胜方。

解:网上的解释大部分都是通过枚举得到的结论,并没有详细的解释和充分的理由。

http://poj.org/showmessage?message_id=41269

这个poj讨论版的解释挺不错的,可以参考一下。


#include<iostream>#include<cstring>#include<cstdio>using namespace std;int main () {    int m, t, i;    while (~scanf("%d", &m)) {        t = 1, i = 0;        while (t < m) {            if (i % 2 == 0) {                t *= 9;            } else {                t *= 2;            }            i ++;        }        if(i % 2 == 1) {            printf("Stan wins.\n");        } else {            printf("Ollie wins.\n");        }    }    return 0 ;}

和那个思路差不多,就是模拟这一情况。O(1)就按照讨论版思路的吧。

0 0
原创粉丝点击