ZOJ 1913 J-Eucild's Game
https://vjudge.net/contest/67836#problem/J
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 wins
时间复杂度:$O(logn)$
题解:博弈论
代码:
#include <bits/stdc++.h>
using namespace std; int S, D; int main() {
while(~scanf("%d%d", &S, &D)) {
if(S == 0 && D == 0) break;
if(S < D) swap(S, D);
if(S == D || S % D == 0) {
printf("Stan wins\n");
} else {
int i;
for(i = 1;; i ++) {
if(S / D == 1) {
int l=S;
S = D;
D = l % D;
continue;
}
if(S / D >= 2) {
break ;
} }
if(i % 2 == 0)
printf("Ollie wins\n");
else
printf("Stan wins\n");
} }
return 0;
}
ZOJ 1913 J-Eucild's Game的更多相关文章
- HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题
第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...
- 137 - ZOJ Monthly, November 2014 - J Poker Face
Poker Face Time Limit: 2 Seconds Memory Limit: 65536 KB As is known to all, coders are lack of ...
- zoj 4122 Triangle City 2019山东省赛J题
题目链接 题意: 给出一个无向图,类似三角形的样子,然后给出边的权值,问找一条从第一个点到最后一个点的路径,要求每一条边只能走一次,并且权值和最大,点可以重复走. 思路: 首先观察这个图可以发现,所有 ...
- ZOJ 4067 Books (2018icpc青岛J) (贪心)
题意 给你一个长度为n的数组,代表每一个物品的价格.你有一个初始钱数\(x\),采用以下方法贪心: 从\(1\)到\(n\)扫一遍,如果\(x\)不比\(a[i]\)小,就买下它,买不起就跳过. 给你 ...
- ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
- ZOJ
某年浙大研究生考试的题目. 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. zoj能AC:2. 若字符串形式为xzojx,则也能AC, ...
- ZOJ 3201 Tree of Tree
树形DP.... Tree of Tree Time Limit: 1 Second Memory Limit: 32768 KB You're given a tree with weig ...
随机推荐
- Hive的内置函数
定义: UDF(User-Defined-Function),用户自定义函数对数据进行处理. UDTF(User-Defined Table-Generating Functions) 用来解决 输入 ...
- 1. Linux内核的配置与裁减:
一.内核的配置和编译流程: 1)编写driver及其子目录下的Kconfig文件,将驱动的配置项写入menuconfig配置界面:2) 执行make menuconfig命令,进入内核配置界面,将对 ...
- 决策树&随机森林
参考链接: https://www.bilibili.com/video/av26086646/?p=8 <统计学习方法> 一.决策树算法: 1.训练阶段(决策树学习),也就是说:怎么样构 ...
- redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect time out
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect ti ...
- python--模块之time,datetime时间模块
time: 表示时间的三种方式:时间戳.格式化的时间字符串.元组时间戳是计算机能够识别的时间:时间字符串是我们能够看懂的时间:元组是用来操作时间: 导入时间模块import time 1,时间戳(ti ...
- 【blockly教程】第三章Blockly顺序程序设计
3.1 什么是Blockly语言 2012年6月,Google发布了完全可视化的编程语言Google Blockly,整个界面清晰明了, 你可以如同在玩拼图一样用一块块图形对象构建出应用程序.每个图 ...
- 北京Uber优步司机奖励政策(1月23日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 佛山Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- nodejs学习笔记(2)
1.express超时设置 如果http请求在一段时间内没有返回值,express会重新向后台发送请求.在后台方法执行时间较长的情况下,重复的请求会重复执行,造成前台接收到空的response,出现E ...
- 100万套PPT模板,包含全宇宙所有主题类型PPT,绕宇宙100圈,持续更新
100万套PPT模板,包含全宇宙所有主题类型PPT(全部免费,都是精品,没有一张垃圾不好看的PPT,任何一张PPT拿来套入自己的信息就可以立马使用),绕宇宙100圈,任意一个模板在某文库上都价不菲.强 ...