一、题目描述

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 711 74 74 31 31 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:Sunywhile(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;
}

转载于:https://www.cnblogs.com/chenximcm/p/6285141.html

SicilyFunny Game相关推荐

最新文章

  1. webpack使用和踩过的坑
  2. 糖果传递 (数学题)
  3. 让Keras更酷一些:中间变量、权重滑动和安全生成器
  4. 如何在SAP gateway系统配置路由到后台系统的OData服务路径
  5. 全国计算机等级考试题库二级C操作题100套(第73套)
  6. 02.2-元素定位(XPath)
  7. 蒟蒻吃药计划-治疗系列 #round6 数据结构初步-指针|链表|结构体
  8. 风控算法知识——浅谈信息熵与IV值应用介绍
  9. Windows核心编程_组件透明
  10. 使用div模拟table
  11. ff14自动琴谱(成功版)
  12. 【期末复习】计算机算法设计与分析
  13. [MSSQL]如何获取日期月份的英文缩写
  14. 简单拖拉拽就能做数据可视化分析图表
  15. JAVA程序设计题——英雄对战游戏,定义一个描述战斗单位的英雄(Hero)类,此类必须包含以下成员变量:名称(name),生命值(life),技能1攻击力(damage1),防御力(defence)
  16. 计算机文件保存方式,Word文档的三种保存方式
  17. UniPro、Bugzilla和Teambition 缺陷管理工具优劣势对比
  18. python连接数据库实现登录注册_python实现非数据库模式的用户注册和登录
  19. python-字符串容器
  20. 【报告分享】2020-2021年中国购物中心消费者洞察报告-中国连锁经营协会(附下载)

热门文章

  1. mysql中字典值怎么添加_插入Python字典中的值,包括MySQL的键
  2. java 插件开发 互相依赖_java – Eclipse插件开发:有没有办法控制有关我的插件缺少依赖项的安装程序消息?...
  3. 秦九韶算法matlab实验报告,数值分析上机实验报告.doc
  4. python单元测试框架unittest介绍和使用_Python+Selenium框架设计篇之-简单介绍unittest单元测试框架...
  5. openMVS-编译
  6. 显示 grep 结果的指定行
  7. C++ 构建最小堆、最大堆
  8. android 系统源码调试 局部变量值_如何方便快速的整编Android 9.0系统源码?
  9. python调用带参函数_Python | 带有示例的函数调用类型
  10. Java File类void deleteOnExit()方法(带示例)