POJ 2348 Euclid Game (模拟题)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7942 | Accepted: 3227 |
Description
25 7
11 7
4 7
4 3
1 3
1 0
an Stan wins.
Input
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
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 wins 可以参考:《基础训练题解》哈尔滨出版社 俞经善...等编
题意讲解:两个人Ollie和Stan玩一个游戏,每次输入两个非负数。 Stan为先手,Ollie为后手。
每次从大数中减去小数的任意倍数,将其减完后的结果赋值给被减的大数。Ollie刚才的游戏规则,
然后进行循环。直到小数不能再大数中拿到一个非0的数为止。最后一个拿到数的玩家为赢家。 算法讲解:大数除以小数,当值大于1时,正在进行此次游戏的玩家为赢家。否则要继续游戏。
当游戏进行了偶数次的时候,就是Stan赢,否则就是Ollie赢了。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm> using namespace std; int main()
{
int x, y;
while(scanf("%d %d", &x, &y)!=EOF)
{
if(x==0 && y==0) break; int dd;
int cnt=0; //记录游戏进行次数
int n=x; int m=y;
while(n!=0 && m!=0 )
{
if(m>n){
cnt++;
dd = m/n;
m=m%n; //大数被赋值成那个差值
if(dd >= 2) break;
}
else{
cnt++;
dd=n/m;
n=n%m;
if(dd>=2 ) break;
}
}
if(cnt%2==1) printf("Stan wins\n");
else
printf("Ollie wins\n");
}
return 0;
}
POJ 2348 Euclid Game (模拟题)的更多相关文章
- poj 2348 Euclid's Game 题解
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9023 Accepted: 3691 Des ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- POJ 2348 Euclid's Game 博弈论
http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...
- POJ 2348 Euclid's Game(博弈)题解
题意:有a,b两个数字,两人轮流操作,每次可以选择两个之中较小的数字,然后另一个数字减去选择数字的任意倍数(不能减到负数),直到其中一个为0,不能操作为败 思路:这题用博弈NP思想,必败点和必胜点之间 ...
- POJ 2348 Euclid's Game(辗转相除博弈+自由度分析)
题目链接:http://poj.org/problem?id=2348 题目大意:给你两个数a,b,Stan和Ollie轮流操作,每次可以将较大的数减去较小的数的整数倍,相减后结果不能小于0,谁先将其 ...
- POJ 2348 Euclid's Game(博弈论)
[题目链接] http://poj.org/problem?id=2348 [题目大意] 给出两个数,两个参赛者轮流用一个数减去另一个数的倍数,当一个数为0的时候游戏获胜, 求先手是否必胜 [题解] ...
- POJ 2348 Euclid's Game【博弈】
题目链接: http://poj.org/problem?id=2348 题意: 给定两个数,两个人每次从较大数中减去较小数的倍数,谁先得到0谁获胜,为谁赢? 分析: 令一种可能出现的整数对为(a,b ...
- POJ 2348 Euclid's Game(简单博弈)
这道题没说a b最大多少,所以要声明为long long型,不然会WA! 道理很简单,(默认a>=b)a和b只有以下三种关系: 1.a%b==0 :这种关系下,可能是a/b为整数,也可能是a和b ...
随机推荐
- PowerDesigner16 安装包及破解文件
一.准备工作 PowerDesigner16 安装包:http://pan.baidu.com/s/11Qv9H 或http://cloud.suning.com/cloud-web/share/li ...
- Git修改IP重新定位的方法
进入已clone项目的.git文件夹,打开config文件 打开config,如图显示,修改url中的IP为192.168.6.102,然后保存 在项目上右击选择属性(R),然后选择Git,即可看到当 ...
- 纯CSS实现的很酷的卡通肖像和眨眼动效
产品设计技术趋势 当前产品设计和开发的一个主要技术趋势除了响应式外, 还有尽量使用CSS/HTML5技术替代图片,这样能够获得非常好的设计扩展性和页面訪问性能. CSS卡通实例 以下就是一个英国WEB ...
- Web开发框架 SSH 简介
Struts 是一个很好的MVC框架,主要技术是Servlet和Jsp.Struts的MVC设计模式可以使我们的逻辑变得很清晰,让我们写的程序层次分明. 官方地址:http://struts.apac ...
- 微信小程序-封装请求(GET、POST)
使用:先导入到util.js 最后在页面上导入util.js(路径自改) var util = require('../../util.js'); 使用示例GET:util.SEND(url,'GET ...
- GSL 1.15 and 1.16 building with Visual Studio 2010 --FROM 4fire
http://4fire.wordpress.com/2012/03/18/gsl-1-15-building-with-visual-studio-2010/ Update 05/02/2014: ...
- CSS3 background属性
background: #00FF00 url(bgimage.gif) no-repeat fixed top; background 简写属性在一个声明中设置所有的背景属性. 可以设置如下属性: ...
- [Java开发之路](23)装箱与拆箱
1. 简单介绍 大家对基本数据类型都很熟悉.比如 int.float.double.boolean.char 等.基本数据类型是不具备对象的特性,比方基本类型不能调用方法.功能简单. ..,为了让基本 ...
- VESA-ADV7123-SOCKIT-DE2115
/*--VGA Timing--Horizontal :-- ______________ _____________-- | | |--_______________| VIDEO |_______ ...
- NativeBase准备工作
环境 node>= 4.0 npm>= 3.0 rnpm (only if React Native version < 0.29) ReactNativeCLI 安装及运行 ht ...