POJ - 2348 Euclid's Game
来源:互联网 发布:sql中select语句实例 编辑:程序博客网 时间:2024/06/01 08:27
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):
an Stan wins.
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 1215 240 0
Sample Output
Stan winsOllie wins#include <cstdio>#include <algorithm>using namespace std;int main() {int a, b;while (scanf("%d%d", &a, &b) && a + b) {bool flag = true;while (true) {if (a > b) swap(a, b);if (b % a == 0) break;if (b - a > a) break;b -= a;flag = !flag;}if (flag) puts("Stan wins");else puts("Ollie wins");}return 0;}
0 0
- poj 2348 Euclid's Game
- POJ-2348-Euclid's Game
- poj 2348 Euclid's Game
- poj 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ - 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ 2348 Euclid's Game
- poj 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ 2348 Euclid's Game
- zoj 1913 || poj 2348 Euclid's Game
- POj-2348-Euclid's Game-博弈
- POJ 2348 Euclid's Game(博弈)
- POJ 2348 Euclid's Game 组合游戏
- POJ 2348-Euclid's Game(博弈论)
- Euclid's Game - POJ 2348 博弈论
- MFC实现的串口测试程序
- iOS 判断当前屏幕旋转状态
- 学习JAVA开发心得第一篇
- BZOJ 2440 & 2301 莫比乌斯应用
- 关于iOS多线程
- POJ - 2348 Euclid's Game
- dbms_sql包的用法
- 为何stop()和suspend()方法不推荐使用
- hdoj 1789 Doing Homework again
- Equivalent Strings(Codeforces Round #313 (Div. 2) D)
- 《汇编语言》第二版 王爽著 第五章 [BX]和loop指令 要点
- HDU - 1875畅通工程再续-最小生成树
- java中注解的使用与实例(一)
- Unity5新的AssetBundle系统使用心得