POJ 2348 (博弈)
来源:互联网 发布:淘宝嘉贝逸飞旗舰店 编辑:程序博客网 时间:2024/06/09 14:40
Euclid's Game
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8502 Accepted: 3451
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
Source
Waterloo local 2002.09.28
题意:给出两个整数,每一次都用大整数减去小整数的倍数,率先出现0的人获胜。
对于当前状态1,不管过程如何两个整数(n, m)(n>=m)都将会变成状态2:(m, n%m),所以如果状态2必败,那么状态1就必胜;否则的话考虑n最多减去几次m,如果n/m的结果取整大于1,那么先手就可以使状态变成(n%m+m, m)从而必胜,否则必败。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;bool win (int n, int m) { if (m == 0) return 0; if (!win (m, n%m)) return 1; int t = n/m; if (t > 1) return 1; return 0;}int main () { int n, m; while (scanf ("%d%d", &n, &m) == 2) { if (!n && !m) break; if (n < m) swap (n ,m); printf ("%s\n", win (n, m) ? "Stan wins" : "Ollie wins"); } return 0;}
0 0
- poj 2348(博弈)
- poj 2348 欧几里得博弈
- POJ 2348 (博弈)
- POJ 2348 —— 博弈
- poj博弈
- POJ 2348 欧几德里博弈,博弈好题
- POj-2348-Euclid's Game-博弈
- POJ 2348 Euclid's Game(博弈)
- POJ 2348 Euclid's Game【博弈】
- 博弈______Euclid's Game( poj 2348 )
- 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 2484(博弈-对称博弈)
- 博弈题 poj 1143
- DWR 学习及深入
- 格式化输出--%m.n
- 安装HomeBlew
- 微信订阅号 45009 报错
- How to create a new user and grant permissions on MySql
- POJ 2348 (博弈)
- [292] Nim Number
- 64位 Ubuntu 14 安装校园上网H3C客户端iNode
- java的定时器功能
- Android中Service服务详解(二)
- caffe 在windows系统下的配置,以及matlab接口配置
- 关于ViewDragHelper通过addView动态修改UI的坑
- React Native-17.React Native 常用API及实践 AppStateIOS StatusBarIOS
- GIT服务器搭建 gitosis 篇 系列1