POJ 2348 Euclid's Game (博弈)
题意:给定两个整数,两个人轮流操作,每次可以用较大数减去较小数的整数倍,当一个数变成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 (博弈)的更多相关文章
- poj 2348 Euclid's Game 题解
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9023 Accepted: 3691 Des ...
- 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谁获胜,为谁赢? 分析: 令一种可能出现的整数对为(a,b ...
- POJ 2348 Euclid's Game(简单博弈)
这道题没说a b最大多少,所以要声明为long long型,不然会WA! 道理很简单,(默认a>=b)a和b只有以下三种关系: 1.a%b==0 :这种关系下,可能是a/b为整数,也可能是a和b ...
- POJ 2348 Euclid's Game 博弈论
http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...
- POJ 2348 Euclid's Game(博弈论)
[题目链接] http://poj.org/problem?id=2348 [题目大意] 给出两个数,两个参赛者轮流用一个数减去另一个数的倍数,当一个数为0的时候游戏获胜, 求先手是否必胜 [题解] ...
- poj 2348 Euclid's Game
题目: 给两个整数a和b,两个人先后用较大的数减去较小数的整数倍,并且保证相减后为非负数.先把一个数变为0的人获胜. 分析: 很显然,当大数是小数的整数倍时为必胜态. 从这道题学会一个叫做自由度的东西 ...
- POJ 2348 Euclid Game (模拟题)
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7942 Accepted: 3227 Des ...
随机推荐
- svn服务的安装和使用
更新linux软件库 cat /etc/redhat-release wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.c ...
- linux c编程:gdb的使用
首先用一个简单的打印字符的程序来做下示例 #include<stdio.h>#include<string.h>void main(){ int i=0; char ...
- 采集练习(十一) php 获得电视节目预告---数据来自电视猫
昨天写了个采集搜视网的电视节目预告,刚好今天有心情,想采下其他网站提供的节目预告,发现 电视猫wap版 的提供的节目预告也蛮好采(需要正则)....感谢移动互联网! 电视猫的 wap版地址是 htt ...
- API的理解和使用——列表类型的命令
列表类型的命令及对应的时间复杂度 操作 命令 功能 时间复杂度 添加 rpush key value [value ...] 向右插入 O(k),k是元素个数 lpush key value [val ...
- Java for LeetCode 092 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...
- Contiki 2.7 Makefile 文件(一)
一.主控Makefile 这里以hello-world例子为主线,从其工程Makefile开始,解析整个build过程.
- 对C++指针的一个比喻
假如你身在上海,你的电脑出了一点问题,你解决不了,这时你想起了你的远在北京的朋友小D,此时小D打开了他的心爱的笔记本... c++中函数的参数传指针就像你用teamviewer与你的朋友小D建立连接, ...
- C#多线程编程介绍——使用thread、threadpool、timer
C#多线程编程介绍——使用thread.threadpool.timer 在system.threading 命名空间提供一些使得能进行多线程编程的类和接口,其中线程的创建有以下三种方法:thread ...
- C#高性能Socket服务器SocketAsyncEventArgs的实现(IOCP)
网址:http://blog.csdn.net/zhujunxxxxx/article/details/43573879 引言 我一直在探寻一个高性能的Socket客户端代码.以前,我使用Socket ...
- checkbox怎么判断是否选中
下面这种可以使用 if($("#checkbox1").is(':checked')) { alert("1"); } else { alert("0 ...