题意:给定两个整数,两个人轮流操作,每次可以用较大数减去较小数的整数倍,当一个数变成0时,则结束,问谁会胜。

析:很明显如果 a == b 那么就可以直接结束了,那么如果 a > b我们可以交换两个数,保证 a < b。可以分成两类,

(1) b - a < a (2)  b - a > a

对于第一类,只能一种拿法,只能是从 b 中拿去 a。对于第二种,如果 b 减去 a 后是必败态,那么当前就是必胜态,如果得到是必胜态,那么当前就是必败态,

我们假设 b - ax < a,如果 b - a(x-1)后是必败态,那么就可以直接减去,如果 b - a(x-1) 后是必胜态,那让b - ax 得到就是必败态。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e6 + 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
while(scanf("%d %d", &n, &m) == 2 && m+n){
bool ok = true;
while(1){
if(m > n) swap(m, n);
if(n % m == 0) break;
if(n - m > m) break;
n -= m;
ok = !ok;
}
printf("%s\n", ok ? "Stan wins" : "Ollie wins");
}
return 0;
}

  

POJ 2348 Euclid's Game (博弈)的更多相关文章

  1. poj 2348 Euclid's Game 题解

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9023   Accepted: 3691 Des ...

  2. POJ 2348 Euclid's Game(博弈)题解

    题意:有a,b两个数字,两人轮流操作,每次可以选择两个之中较小的数字,然后另一个数字减去选择数字的任意倍数(不能减到负数),直到其中一个为0,不能操作为败 思路:这题用博弈NP思想,必败点和必胜点之间 ...

  3. POJ 2348 Euclid's Game(辗转相除博弈+自由度分析)

    题目链接:http://poj.org/problem?id=2348 题目大意:给你两个数a,b,Stan和Ollie轮流操作,每次可以将较大的数减去较小的数的整数倍,相减后结果不能小于0,谁先将其 ...

  4. POJ 2348 Euclid's Game【博弈】

    题目链接: http://poj.org/problem?id=2348 题意: 给定两个数,两个人每次从较大数中减去较小数的倍数,谁先得到0谁获胜,为谁赢? 分析: 令一种可能出现的整数对为(a,b ...

  5. POJ 2348 Euclid's Game(简单博弈)

    这道题没说a b最大多少,所以要声明为long long型,不然会WA! 道理很简单,(默认a>=b)a和b只有以下三种关系: 1.a%b==0 :这种关系下,可能是a/b为整数,也可能是a和b ...

  6. POJ 2348 Euclid's Game 博弈论

    http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...

  7. POJ 2348 Euclid's Game(博弈论)

    [题目链接] http://poj.org/problem?id=2348 [题目大意] 给出两个数,两个参赛者轮流用一个数减去另一个数的倍数,当一个数为0的时候游戏获胜, 求先手是否必胜 [题解] ...

  8. poj 2348 Euclid's Game

    题目: 给两个整数a和b,两个人先后用较大的数减去较小数的整数倍,并且保证相减后为非负数.先把一个数变为0的人获胜. 分析: 很显然,当大数是小数的整数倍时为必胜态. 从这道题学会一个叫做自由度的东西 ...

  9. POJ 2348 Euclid Game (模拟题)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7942   Accepted: 3227 Des ...

随机推荐

  1. EasyNVR如何实现跨域鉴权

    EasyNVR提供简单的登录鉴权,客户端通过用户名密码登录成功后,服务端返回认证token的cookie, 后续的接口访问, 服务端从cookie读取token进行校验. 但是, 在与客户系统集成时, ...

  2. Dijkstra的堆优化

    先附上一个例题:P3371 [模板]单源最短路径 一眼扫去,最短路... spfa可行,但是今天的主题是Dijkstra: #include<iostream> #include<a ...

  3. 怎样拆分View Controller进而实现轻量级的View Controller[UIKit]

    參考文章来自objcio站点   为什么要编写轻量级的View Controller??   1.作为iOS项目中最大的文件,ViewControllers中的代码复用率差点儿是最低的 2.重量级的V ...

  4. Java for LeetCode 123 Best Time to Buy and Sell Stock III【HARD】

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  5. File.basename

    File.basename函数 返回filename中的最后一条斜线后面的部分.若给出了参数suffix且它和filename的尾部一致时,该方法会将其删除并返回结果. 例: p File.basen ...

  6. 20145239 Linux下常用的ls命令总结

    20145239 Linux下常用的ls命令总结 通过学习本周的教学视频和要求掌握的内容,发现ls命令被使用的次数非常多,但作为一个初学者,可能我只会ls或者顶多ls -l两种用法.但其实ls是一个非 ...

  7. BZOJ 1196 [HNOI2006]公路修建问题:二分 + 贪心生成树check(类似kruskal)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1196 题意: n个城市,m对城市之间可以修公路. 公路有两种,一级公路和二级公路,在第i对 ...

  8. Queue Explorer过期处理

    Queue Explorer是收费软件,用一段时间后会显示过期界面无法使用, 我们可以删除注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cogin\Queue ...

  9. bzoj1177&p3625 [APIO2009]采油区域p[大力讨论]

    我好菜菜啊. 给定矩形,从中选出三个边长K的正方形互不重叠,使得覆盖到的数总和最大. 想的时候往dp上钻去了..结果一开始想了一个错的dp,像这样 /************************* ...

  10. bzoj 2216: Lightning Conductor 单调队列优化dp

    题目大意 已知一个长度为\(n\)的序列\(a_1,a_2,...,a_n\)对于每个\(1\leq i\leq n\),找到最小的非负整数\(p\)满足: 对于任意的\(j\), \(a_j \le ...