(博弈论)hdoj 1525 Euclid's Game】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1525 题目大意:Stan和Ollie在玩一个游戏,a和b两个数字,每次可以选择较大的数减去较小的数的若干倍,最后将大数减为0的人获胜.问给定的两个数字,谁会获胜. 后来的思路最后必然的局面是b,a%b,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况.而a/b>=2的话,先手可以选择由谁面对b,a%b这样的局势,每一次的选择也可以决定后一次的抉择…
自己想明白的第一道博弈.首先a==b的时候肯定是先手赢: 然后当a>=2*b时,不妨假设a=nb+k, k<b,因此,不论后续怎么博弈,一定可以出现a=k, b=b的情况.因此,无论这个局面是胜或负,先手者一定可以得到利于自己的局面.若(k,b)为负,则先手者从a减去nb,则先手胜:若(k,b)为胜,先手者从a减去(n-1)*b,则先手仍然胜. 当b<a<2*b时,只能对a减去b,然后进入下一轮仍旧按照上述策略博弈. /* 1525 */ #include <cstdio&g…
思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面,只可能到b,a%b,没有选择.而a/b>=2的话,先手可以选择由谁面对b,a%b这样的局势,先手在a/b>=2的局面必胜 代码如下: #include<stdio.h> #include<iostream> #include<algorithm> #includ…
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…
Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3174    Accepted Submission(s): 1474 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan,…
Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1256    Accepted Submission(s): 576 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan,…
题目大意: 题目给出了两个正数a.b 每次操作,大的数减掉小的数的整数倍.一个数变为0 的时候结束. 谁先先把其中一个数减为0的获胜.问谁可以赢.Stan是先手. 题目思路: 无论a,b的值为多少,局面:[a%b,b] 一定会出现. 双方都足够聪明,无论谁都知道这种局面是必胜局面还是必败局面 若是必败局面操作者为了获胜,直接到达[a%b,b]局面就可以(将必败局留给对方) 若是必胜局操作者为了获胜,到达[a%b+b,b]局面(经过对手操作后,将必胜局面留给自己) #include<stdio.h…
假设当前b>a. 一.b%a==0 必胜 二.b<2*a,当前我们没有选择的余地,若下一步是必胜(最终能到情况一),则当前必败:反之,当前必胜. 三.b>2*a,假设x是使得b-ax<a的整数,考虑一下从b中减去a(x-1)的情况,例如对于(4,19)则减去12. 此时,接下来的状态就成了前边讲过的没有选择余地的情况二,若该状态是必败态的话,当前状态就是必胜态. 若该状态是必胜态的话,其下一步是唯一确定的,因此是必败态,所以我们可以直接到达此态. ∴情况三是必胜态. ∴先达到情况一…
题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P(必胜态) 始终假设b>=a 那么(a,b)b%a==0 , 那么就是 必败态 N 如果2*a>b>a 那么只能选择进入 (a , b-a)不确定什么状态 因为每个人都很聪明,所以对于碰到一个a ,b的局面 如果 b>a*2 , 那么应该知道 (a , b%a) 是不是一个必胜态,如果…
Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2074    Accepted Submission(s): 924 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan,…
Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9033   Accepted: 3695 Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser o…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1404 一看就是博弈论的题目,但并没有什么思路,看了题解,才明白 就是求六位数的SG函数,暴力一遍,打表就OK. 具体的操作是先找P态,即最终无法移动的状态,可知无数可取是P态,0是N态,1是P态,然后从1开始进行暴力, 所有可以到!sg[i]的点标记为N态,暴力过程为标记一步可以到sg[i]的数,包括两类: 一类是仅某一位数字不同,提取方法比较巧妙: ; --i){ int m = x; ; ; j…
http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或递归)处理.两种写法都能在题目下面的discuss中找到. 1.找规律,我在这里直接复制了discuss中大神算出的sg函数表(在考试中这种写法是很值得借鉴的,这里就体现出代码能力的重要了,找规律天下第一!). 我算了一下前 30 × 30 的 Sprague-Grundy 函数表,如下: 0 1…
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60481118 由于今天考了一道博弈的问题,我竟什么都不会!于是把之前大佬的讲稿翻出来从头学起 博弈论的基础嘛,就先不提什么SG函数了.简单的讲讲如何判断先手必胜还是必败吧. 每一个状态会有多个后继状态(即走了一步之后的状态),每一个状态都有一个属性:先手必胜 或 先手必败(先手是相对于这一状态). 如果一个状态的后继状态中有必败态,那么当前状态的先手就可…
感觉这道题用PN大法好像不顶用了,可耻地看了题解. 考虑一下简单的必胜状态,某一个数是另一个数的倍数的时候是必胜状态. 从这个角度考虑一下:游戏进行了奇数步还是偶数步决定了哪一方赢. 如果b > 2a,那么这一方就有权利改变游戏步数的奇偶性,从而到达对自己有利的状态,所以这是一个必胜状态. 如果a < b < 2a,那么下一步只能到达(b-a, a)状态,一直模拟就行. #include <cstdio> #include <algorithm> using na…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题解:题目大意,两个人Adam和Eve一块儿玩游戏,游戏规则是从1900年1月1日到2001年11月4日这个时间段内随机选择一天,由Adam开始轮流选择,可以选择后一天,也可以选择下个月的这一天,轮流进行,最后一个选择2001年11月4日的人获得胜利,随机给一个日期,问Adam是否会获胜. 恩,看到题目确实被吓到了,有点不知道从何下手的感觉,还有闰月的干扰,看见别人的分析才明白这个问题实质很简…
以下资料来自:http://blog.csdn.net/Dinosoft/article/details/6795700 http://qianmacao.blog.163.com/blog/static/203397180201222945212647/ http://blog.csdn.net/qinmusiyan/article/details/7950642# HDU 1850 Being a Good Boy in Spring Festival   下面是一个二人小游戏:桌子上有M堆…
[题目链接] http://poj.org/problem?id=2348 [题目大意] 给出两个数,两个参赛者轮流用一个数减去另一个数的倍数,当一个数为0的时候游戏获胜, 求先手是否必胜 [题解] 如果出现一个数是另一个数两倍以上的时候,操作者就拥有了一定的自由度, 也就是处于必胜态,那么只要判断谁先到有自由操作的状态或者胜利的状态,谁就必胜. [代码] #include <cstdio> #include <algorithm> using namespace std; int…
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…
Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9023   Accepted: 3691 Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser o…
Luogu P1290 欧几里得的游戏/UVA10368 Euclid's Game 对于博弈论的题目没接触过多少,而这道又是比较经典的SG博弈,所以就只能自己来推关系-- 假设我们有两个数$m,n$,我们先把$m$设为较大值,$n$设为较小值.现在我们把它分成三种情况: 1.若两数为倍数关系,当前操作的一方赢. 2.若$m \div n>1$,那么还是操作一方赢. 为什么呢? 拿$(25,7)$来举例.这时的操作方就有三种选择:$(8,7)$,$(11,7)$,$(4,7)$, 如果他选$(1…
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g…
Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2853    Accepted Submission(s): 1525 Problem Description You are building a house. You’d prefer if all the walls have a precise right…
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of…
Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5994    Accepted Submission(s): 2599 Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one up…
题目描述: Euclid's Game Time Limit: 2 Seconds      Memory Limit: 65536 KB 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 t…
背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东(队长)出战,[并说中国队不胜就再不参加最强大脑]3局过后,打平,双方都没脑力进行下一轮,所以评委各得1分,结果:1V1. 2:苏XX(忘名了)出战,打败对手,结果:2V1. 3:申一帆出战,失败,结果2V2平(同时申一帆情绪失控离开节目现场,经节目组一番说辞后回归节目) 问题来了:最后一战,谁出站,在大屏幕播…
Euclid求最大公约数算法 #include <stdio.h> int gcd(int x,int y){ while(x!=y){ if(x>y) x=x-y; else y=y-x; } return x; } int main(int argc, const char *argv[]) { if(3!=argc){ printf("Usage:<a,out> num1 num2\n"); return -1; } printf("%d\…
Problem Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color…
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛时发现相同值的时候,判断两条路径的字典序 代码 #include "stdio.h" const int MAXN=110; const int INF=10000000; bool vis[MAXN]; int pre[MAXN]; int cost[MAXN][MAXN],lowcos…