一、题目描述

Two players, Singa and Suny, play, starting with two natural numbers. Singa, 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 Suny, the second player, does the same with the two resulting numbers, then Singa, 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 Singa wins.

二、输入

The input consists of a number of lines. Each line contains two positive integers (<2^31) giving the starting two numbers of the game. Singa always starts first. The input ends with two zeros.

三、输出

For each line of input, output one line saying either Singa wins or Suny wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.

四、解题思路

一开始,看完题目完全没头绪,不知道从何下手。后来想想,这是一个博弈游戏,按照游戏规则,如果其中一个数不比另外一个数大一倍或一倍以上时,游戏将进行简单地相减。

if(nultipleNum2 > nultipleNum1)
nultipleNum2 -= nultipleNum1;

如果,出现一个数是另外一个数的n倍,游戏结束。

当其中一个数是另外一个数的二倍以上(n倍)时,这时玩家可以根据逆推的方法选择减去n倍或者n-1倍,以达到让自己赢的情况。

五、代码

#include<iostream>

using namespace std;

int main()
{
int num1, num2;
cin >> num1 >> num2; while(num1 || num2)
{
int nultipleNum1, nultipleNum2;
nultipleNum1 = num1;
nultipleNum2 = num2;
int result = 0; //记录轮到谁,1:Singa,0:Suny while(nultipleNum1 && nultipleNum2) //如果两个数都大于0,游戏继续
{
result++;
result %= 2;
if(nultipleNum1 > nultipleNum2)
{
if(nultipleNum1 / nultipleNum2 >= 2) break; //当遇到一个数是另外一个数的两倍或两倍以上时,即能赢得游戏
else nultipleNum1 -= nultipleNum2;
}else
{
if(nultipleNum2 / nultipleNum1 >= 2) break;
else nultipleNum2 -= nultipleNum1;
}
} if(result == 1) cout << "Singa wins" << endl;
else cout << "Suny wins" << endl; cin >> num1 >> num2;
} return 0;
}

<Sicily>Funny Game的更多相关文章

  1. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  2. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  3. 大数求模 sicily 1020

        Search

  4. Sicily 1510欢迎提出优化方案

    这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...

  5. sicily 1063. Who's the Boss

    Time Limit: 1sec    Memory Limit:32MB  Description Several surveys indicate that the taller you are, ...

  6. 【sicily】 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  7. Sicily 1215: 脱离地牢(BFS)

    这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...

  8. Sicily 1153: 马的周游问题(DFS+剪枝)

    这道题没有找到一条回路,所以不能跟1152一样用数组储存后输出.我采用的方法是DFS加剪枝,直接DFS搜索会超时,优化的方法是在搜索是优先走出度小的路径,比如move1和move2都可以走,但是如走了 ...

  9. Sicily 1151: 简单的马周游问题(DFS)

    这道题嘛,直接使用DFS搜索,然后莫名其妙地AC了.后来看了题解,说是move的顺序不同的话可能会导致超时,这时便需要剪枝,真是有趣.原来自己是误打误撞AC了,hhh.题解还有另一种解法是先把一条完整 ...

  10. Sicily 1048: Inverso(BFS)

    题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...

随机推荐

  1. UVA 11971 - Polygon 数学概率

                                        Polygon  John has been given a segment of lenght N, however he n ...

  2. javascript系列-class4.函数

    欢迎加入前端交流群来py: 转载请标明出处!                   在火影的世界中存在忍术,忍术是把强大的能量集中在一起以各种各样不同的形式发射出来.怎样使用各种各样的忍术那?通过结印. ...

  3. SharePoint 使用Expression Web 设计网站

    创建好网站以后可就可以开始发布了 possible causes : 1.The web server may not hava the FrontPage Server Extensions ins ...

  4. MyBatis数据持久化(二)建立数据库会话

    上篇文章中介绍了我们使用mybatis前的准备工作,并在程序中通过jdbc与mysql数据库成功建立连接,接下来介绍如何使用mybatis与数据库建立会话.我们需要以下几个步骤: 1.在build p ...

  5. RGB与16进制色互转

      点击进入新版 <前端在线工具站> CSS, JavaScript 压缩YUI compressor, JSPacker...HTML特殊符号对照表PNG,GIF,JPG... Base ...

  6. JavaScript学习——使用JS完成全选和全不选操作

    1.我们希望在后台系统实现一个批量删除的操作(全选所有的复选框)和全不选,显示效果如下: 2.步骤分析: 第一步:确定事件(onclick)并为其绑定一个函数(事件绑定到编号前面的复选框里面) 第二步 ...

  7. C语言-实现字符串倒序输出

    方法1: Action(){//倒序输出 char *src="abcdefgh123"; char *desc; desc=(char *)malloc(100*sizeof(c ...

  8. 大数相乘(牛客网ac通过)

    2019-05-172019-05-17 大数相乘基本思想: 相乘相加,只不过大于10先不进位到计算完后统一进位 #include <iostream> #include <stri ...

  9. 洛谷P2607 [ZJOI2008]骑士 基环树动归

    Code: #include<algorithm> #include<cstdio> #include<algorithm> #include<cstring ...

  10. 【BZOJ4383】[POI2015]pustynia

    题意: 建议Alt+F4百度一下 题解: 差分约束+线段树优化建图,直接按照拓扑序跑就行了 代码: #include<iostream> #include<cstring> # ...