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, 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. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7):

25 7
11 7
4 7
4 3
1 3
1 0

an Stan wins.

 
Input
The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.
 
Output
For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.

 
Sample Input
34 12
15 24
0 0
 
Sample Output
Stan wins
Ollie wins
 
题意:给出了两个正数a.b,每次操作,大的数减掉小的数的整数倍。一个数变为0 的时候结束。

谁先先把其中一个数减为0的获胜。问谁可以赢。Stan是先手。

题解:没想太多打表过的。。

正确题解:

如果a==b.那么肯定是先手获胜。一步就可以减为0,b

如果a%b==0.就是a是b的倍数,那么也是先手获胜。

如果a>=2*b.  那么 那个人肯定知道a%b,b是必胜态还是必败态。如果是必败态,先手将a,b变成a%b,b,那么先手肯定赢。如果是必胜态,先手将a,b变成a%b+b,b.那么对手只有将这两个数变成a%b,b,先手获胜。

如果是b<a<2*b  那么只有一条路:变成a-b,b  (这个时候0<a-b<b).这样一直下去看谁先面对上面的必胜状态。

所以假如面对b < a <2*b的状态,就先一步一步走下去。直到面对一个a%b==0 || a >=2*b的状态。

#include<bits/stdc++.h>
#define N 35
#define mes(x) memset(x, 0, sizeof(x));
#define ll __int64
const long long mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
int dfs(int n, int m){
if(n > m) swap(n,m);
if(n >= *m) return ;
if(n == )
return ;
for(int i=m%n;i<m;i += n){
if(dfs(n, i) == )
return ;
}
return ;
}
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m)&&(n||m))
printf("%s\n", dfs(n,m)?"Stan wins":"Ollie wins");
}

最新文章

  1. Jenkins中构建Testcomplete项目的方法介绍
  2. TFS签入签出规范
  3. 使用ssis完成excel的数据导入
  4. hdu 2846 Repository
  5. 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe
  6. iOS swift lazy loading
  7. php浏览历史记录的方法
  8. 数据库入门之运行原始 SQL 查找
  9. 机器学习基石:07 The VC Dimension
  10. [Swift]LeetCode819. 最常见的单词 | Most Common Word
  11. Day3 Numerical simulation of optical wave propagation之标量衍射理论基本原理(三)
  12. [工作总结]jQuery在工作开发中常用代码片段集锦(1-10)
  13. Gitlab--安装及汉化
  14. Android 创建单独的服务运行在后台(无界面)
  15. Python 数据分析 - 索引和选择数据
  16. 机器学习进阶-图像金字塔与轮廓检测-轮廓检测 1.cv2.cvtColor(图像颜色转换) 2.cv2.findContours(找出图像的轮廓) 3.cv2.drawContours(画出图像轮廓) 4.cv2.contourArea(轮廓面积) 5.cv2.arcLength(轮廓周长) 6.cv2.aprroxPloyDP(获得轮廓近似) 7.cv2.boudingrect(外接圆)..
  17. Linux基础三(软件安装管理)
  18. HttpWebRequest抓取网页数据返回异常:远程服务器返回错误: (503) 服务器不可用
  19. 8、java5线程池之动态缓存线程池newCachedThreadPool
  20. linux的客户端安装步骤配置

热门文章

  1. android中使用startactivityforresult跳转Activity后需要重写onBackPressed()方法
  2. 随手记一次用C#正则表达式获取下拉菜单html标签&lt;select&gt;以及相关属性值
  3. DEDE有无缩略图如何调取
  4. ubuntu-14.04服务器版下搭建apache2+svn+svnmanager服务
  5. vmware在桥接模式下配置centos7网络,并使用xshell连接虚拟主机(总结篇)
  6. ios10 xcode8 适配的那些事
  7. CURL in windows
  8. 更改android AVD模拟器创建路径位置的方法
  9. 安装hadoop集群服务器(hadoop1.2.1)
  10. python入门到精通[二]:基础学习(1)