POJ 2348 Euclid's Game
来源:互联网 发布:js div 位置 编辑:程序博客网 时间:2024/06/05 18:10
<pre><span style="word-wrap: normal; word-break: normal;"><span style="font-size:18px;">题目大意:</span></span>
给两堆石子(题目中是数,配合一下上文这里说石子),两人依次取石子,规则是:每次从石子数较多的那堆取(两堆石子数目相等时任选一堆),取的数目只能为石子少的那一堆的正整数倍。最后取完一堆石子者胜。问给定情况下先手胜负情况。
//现有状态(x,y) (设x>0且y>0,其它情况自行考虑)//(1)当x=y时,显然先手胜//(2)不妨设x<y//那么(x+y,y)的下一步必定为(x,y),所以(x+y,y)和(x,y)的结果必然//相反,其中有一种状态可以先手胜,另一种后手胜//对于任意k>=2,状态(x+ky,y)可以通过从x+ky那堆去掉(k-1)y个石子//变成(x+y,y),也可以通过从x+ky那堆去掉ky个石子变成(x,y),//于是这两种选择(注意:这是自主的选择)必然有一种可以获胜,//所以当k>=2时(x+ky,y)必胜
#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#include <iostream>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#define INF 0x3f3f3f3f#define maxn 500100#define mem(a) memset(a,0,sizeof(a))using namespace std;typedef long long ll;int main(){ int n,m; while(scanf("%d%d",&n,&m) && (n+m)) { int f = 1; while(1) { if(n > m) swap(n,m); if(m - n > n) break; if(m % n == 0) break; m -= n; f = !f; } if(f) puts("Stan wins"); else puts("Ollie wins"); }return 0;}
0 0
- poj 2348 Euclid's Game
- POJ-2348-Euclid's Game
- poj 2348 Euclid's Game
- poj 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ - 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ 2348 Euclid's Game
- poj 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ 2348 Euclid's Game
- POJ 2348 Euclid's Game
- zoj 1913 || poj 2348 Euclid's Game
- POj-2348-Euclid's Game-博弈
- POJ 2348 Euclid's Game(博弈)
- POJ 2348 Euclid's Game 组合游戏
- POJ 2348-Euclid's Game(博弈论)
- Euclid's Game - POJ 2348 博弈论
- Hadoop源码分析之DataNode的启动与停止
- CentOS6.5 ffmpeg m3u8 切片
- 记录一个查询颜色RGB和HSV值还有HTTP状态码等的网站
- Processing 教程(11) - 三角函数的魅力 - 波形
- MAP集合应用
- POJ 2348 Euclid's Game
- struct和union的内存分配
- 【CQOI2006】【BZOJ2618】凸多边形
- 目录与文件的权限意义
- 深入剖析Socket实现
- 关于PHP项目初学
- java通过经纬度计算两个点的之间的距离的算法
- OpenCV配置(Java篇)
- POJ3632解题报告