【POJ 2348 Euclid's Game】 + 博弈

来源:互联网 发布:js函数传对象 编辑:程序博客网 时间:2024/05/22 17:23

Euclid’s Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9172 Accepted: 3756

Description
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7):

     25 7     11 7      4 7      4 3      1 3      1 0

an Stan wins.

Input
The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.

Output
For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.

Sample Input

34 12
15 24
0 0

Sample Output

Stan wins
Ollie w

若出现 N - M > M 情况是否为自由态?

AC代码:

#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;int main(){    LL N,M;    while(scanf("%lld %lld",&N,&M) != EOF){        if(N == 0 && M == 0) break;        bool ok = true;        while(1){            if(N < M) swap(N,M);            if(N % M == 0 || (N > 2 * M)) break;            N -= M;            ok = !ok;        }        if(ok) printf("Stan wins\n");        else printf("Ollie wins\n");    }    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 教师体检来例假怎么办 老板拖欠农民工工资怎么办 公司破产拖欠员工工资怎么办 白玉蜗牛下蛋了怎么办 黄牛卖不出的票怎么办 鸡受风寒不产蛋怎么办 蛋鸡感冒不下蛋怎么办 牛肉煮老了怎么办 牛肉炖碎了怎么办 比值审敛法等于1怎么办 华为手机停止运行怎么办 易事通卡怎么办延期 三星手机照相机故障怎么办 凌晨一点到机场怎么办 凌晨3点醒来怎么办 凌晨四五点咳嗽怎么办 凌晨4点大便怎么办 熊猫小课付了费怎么办 华为手机系统升级后卡机怎么办 孕妇汗脚脚臭怎么办 巴基斯坦留学生丢失护照怎么办 vivox20耳机进水了怎么办 轴圆齿之间间隙大怎么办 浩辰cad2017保存不了怎么办 会议无poster版块怎么办 大四考研失败了怎么办 博士退学老师不同意怎么办? 贴双眼皮眼皮松怎么办 dpf灯亮了怎么办 60岁社保没交满怎么办 老公素质太差怎么办 耿彦波退休了太原怎么办 宫腔镜三天后同房了怎么办 开关失灵关不了怎么办 灯的开关关不掉怎么办? 身上毛孔粗大怎么办呀 脸被牙膏灼伤怎么办 wifi要登录认证怎么办 本科没有选导师怎么办 预授权撤销了怎么办 软件连不上网怎么办