#include<iostream> using namespace std; int GCD(int &a, int &b) { int remainder; if (b != 0) while (true) { remainder = a % b; if (remainder == 0) ret ...
转载
2021-10-29 03:03:00
110阅读
2评论
题目 给定两个整数 a 和 b,Stan和Ollie轮流从较大的数字中减去较小的数的倍数。这里的倍数是指1倍、2倍这样的整数倍,并且相减后的结果不能小于0。Stan先手,在自己的回合将其中一个数变成零的一方获胜。当双方都采取最优策略时,谁会获胜? 分析 不妨设 a<b, 情况一:若b<2a,则(a,
转载
2019-10-05 16:07:00
68阅读
2评论
题目链接:http://poj.org/problem?id=3813Time Limit:1000MSMemory Limit:65536K
Description
In one of his notebooks, Euclid gave a complex procedure for solving the following problem. With computers, per...
原创
2022-02-03 15:06:22
48阅读
题目链接:http://poj.org/problem?id=3813Time Limit:1000MSMemory Limit:65536K
Description
In one of his notebooks, Euclid gave a complex procedure for solving the following problem. With computers, per...
原创
2021-07-14 10:49:02
128阅读
基本算法——辗转相除法
问题:输出两个正整数a,b,且0<a<b, 输出其最大公约数p和最小公倍数q
解法1——
p从a开始,检测p是否能同时整除a和b, 是则停止循环,不是则令p减1,继续检测。
q从b开始,检测q是否能同时被a和b整除,是则停止循环,不是则令q增1,继续检测。
源程序1
#include <stdio.h>
void main()
{
int
转载
2024-08-20 17:30:40
43阅读
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1525 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Descripti
转载
2017-09-12 20:22:00
35阅读
2评论
"题目" include include using namespace std; int dfs(int a,int b,int ans) { if(a%b==0) { return ans; } else if(a b&&a
原创
2022-10-18 13:50:52
41阅读
博弈论 题解:http://blog.sina.com.cn/s/blog_7cb4384d0100qs7f.html 感觉本题关键是要想到【当a-b>b时先手必胜】,后面的就只跟奇偶性有关了 1 //POJ 2348 2 #include 3 #include 4 bool game(int ...
原创
2021-08-04 14:59:15
136阅读
//Time 78ms, Memory 280K#include
using namespace std;
int main()
{ int i,a,b,k; while(cin>>a>>b && (a || b)) { k=0; if(a1) { k++;break; } i=b;b=a%b;a=i;k++; } if(k%2) cout<<"Stan wins"<<endl; else...
转载
2013-05-27 08:41:00
45阅读
2评论
原题链接 考察:博弈论 找规律 思路: 数字太大了,sg函数求不出来,因此只能先打表找规律(然后什么都没看出来) 看了网上的题解才懂怎么找...= = 先分类几种情况: a%b==0,先手必胜 a>b&&b<a<2b. 此时难以直接判定胜负,需要模拟,此时a只有一种选择.达到判定条件退出. a>2*
转载
2021-03-22 08:11:00
82阅读
2评论
b-a>a为必胜态,所以问题就转化为看谁先达到这个状态#include <cstdio>#include <cstring>#
原创
2022-08-17 16:51:17
54阅读
历史上第一个称得上算法的好像就是这个欧几里得算法,其实就是地球人都知道的辗转相除,故又叫“辗转相除法”不要小看她,她是很美的。
简单的描述就是,记gcd(a,b)表示非负整数a,b的最大公因数,那么:gcd(a,b) = gcd(b,a%b)
Euclid算法定义:
gcd(a,b)=gcd(b, a+kb) a,b,k为任意整数,即gcd(a,
原创
2010-10-19 15:26:51
656阅读
Euclid's GameTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1256Accepted Submission(s): 576Problem DescriptionTwo players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the
转载
2013-07-22 08:25:00
31阅读
2评论
感觉这道题用PN大法好像不顶用了,可耻地看了题解。考虑一下简单的必胜状态,某一个数是另一个数的倍数的时候是必胜状态。从这个角度考虑一下:游戏进行了奇数步还是偶数步决定了哪一方赢。如果b > 2a,那么这一方就有权利改变游戏步数的奇偶性,从而到达对自己有利的状态,所以这是一个必胜状态。如果a 2 #...
转载
2015-04-13 20:55:00
59阅读
2评论
方法1:穷举 #include<iostream> using namespace std; int main(){ int m = 123,i;//求11mod123的逆元 for (i = 2; (11*i-1)%123!=0; i++); cout << i; system("pause"); ...
转载
2021-10-31 00:49:00
309阅读
2评论
题意:
给你两个数n、m(假设n>m),问让n-k*m(k要保证n-k*m>=0),如果谁先减出来0的话谁就获得胜利
题解:
当n%m==0的时候先手获胜
当n<2*m的时候,那么只能通过辗转相减来一步一步求结果
当n>2*m的时候,先手获胜。假设这个时候我们已经知道了n%m与m这两个数是先手获胜还是后手获胜,假设是先手获胜,那么我们可以把n变成n%m+m
这个时候后
转载
2019-08-13 11:07:00
42阅读
2评论
数学问题 博弈论
转载
2016-10-13 15:08:00
31阅读
2评论
题意:给出正整数a,b,每次可以用大的数减去小的数的倍数,最后谁操作完出现0就赢
原创
2023-06-09 18:18:17
37阅读
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
转载
2018-02-02 13:21:00
34阅读
Euclid's Game时间限制: 1000ms 内存限制: 65535KB问题描述Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first playe...
转载
2017-05-20 20:14:00
32阅读
2评论