一、题目描述

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. LeetCode -- 求字符串数组中的最长公共前缀

    题目描写叙述: Write a function to find the longest common prefix string amongst an array of strings.就是给定1个 ...

  2. oracle实现自增id

    --oracle实现自增id --创建一张T_StudentInfo表 create table T_StudentInfo ( "id" integer not null pri ...

  3. 50个Android开发技巧(12 为控件加入圆角边框)

    控件的圆角边框能够使你的App看起来更美观,事实上实现起来也非常easy. (原文地址:http://blog.csdn.net/vector_yi/article/details/24463025) ...

  4. vue Render scopedSlots

    render 中 slot 的一般默认使用方式如下: this.$slots.default 对用 template的<slot>的使用没有name . 想使用多个slot 的话.需要对s ...

  5. 5.Git使用详细教程

    转自:https://www.cnblogs.com/seven-ahz/p/7712125.html 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的 ...

  6. Vue.js Ajax动态参数与列表显示

    一.动态参数显示 1.引入js <script type="text/javascript" src="/js/vue.min.js"></s ...

  7. Linux部署之批量自动安装系统之Kickstart篇

    1.         安装   2.         在桌面环境下啊配置   3.         Kickstart之基本配置   4.         Kickstart之安装方法   5.    ...

  8. POJ 2976 Dropping tests【二分 最大化平均值】

    题意:定义最大平均分为 (a1+a2+a3+---+an)/(b1+b2+---+bn),求任意去除k场考试的最大平均成绩 和挑战程序设计上面的最大化平均值的例子一样 判断是否存在x满足条件 (a1+ ...

  9. PHP读xml、写xml(DOM方法)

    <?php /** * 读取的xml的格式 * <urlset> * <url> * <loc>http://www.51buy.com/0.html< ...

  10. 紫书 例题 11-1 UVa 12219 (表达式树)

    这道题看了刘汝佳的代码真的是天秀, 很值得学习. 具体看代码 #include<cstdio> #include<iostream> #include<cctype> ...