uva 10368 - Euclid's Game(博弈)

来源:互联网 发布:excel文档修复软件 编辑:程序博客网 时间:2024/05/16 06:38

题目链接:uva 10368 - Euclid's Game

题目大意:给出两个数,两个人做一个游戏,每次有stan开始操作,每次操作可以从最大的数中取走若干个小的数,即a-kb,a为比较大的数,b为比较小的数,kb为取走的值,k必须为整数,并且kb≤a。如果不能顺利执行操作,则对手胜利。

解题思路:模拟,直到k的最大值不为1时,当前操作者就掌握了主动权,既可以获胜。特殊情况为a=b的时候,stan胜。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main () {    int a, b;    while (scanf("%d%d", &a, &b) == 2 && a + b) {        int s = 0;        if (a != b) {            int x = max(a, b);            int y = min(a, b);            while (true) {                if (x / y > 1)                    break;                x = x%y;                swap(x, y);                s = 1 - s;            }        }        printf("%s wins\n", s ? "Ollie" : "Stan");    }    return 0;}
1 0
原创粉丝点击