<Sicily>Funny Game
一、题目描述
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的更多相关文章
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- 大数求模 sicily 1020
Search
- Sicily 1510欢迎提出优化方案
这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...
- sicily 1063. Who's the Boss
Time Limit: 1sec Memory Limit:32MB Description Several surveys indicate that the taller you are, ...
- 【sicily】 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- Sicily 1215: 脱离地牢(BFS)
这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...
- Sicily 1153: 马的周游问题(DFS+剪枝)
这道题没有找到一条回路,所以不能跟1152一样用数组储存后输出.我采用的方法是DFS加剪枝,直接DFS搜索会超时,优化的方法是在搜索是优先走出度小的路径,比如move1和move2都可以走,但是如走了 ...
- Sicily 1151: 简单的马周游问题(DFS)
这道题嘛,直接使用DFS搜索,然后莫名其妙地AC了.后来看了题解,说是move的顺序不同的话可能会导致超时,这时便需要剪枝,真是有趣.原来自己是误打误撞AC了,hhh.题解还有另一种解法是先把一条完整 ...
- Sicily 1048: Inverso(BFS)
题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...
随机推荐
- node12---mongodb
一.传统数据库技术回顾 数据库就是存储数据的,那么存储数据就用txt就行了啊,为什么要有数据库? 理由之1: 数据库有行.列的概念,数据有关系,数据不是散的. 老牌数据库,比如MySQL.SQL Se ...
- poj--2549--Sumsets(二分查找)
Sumsets Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- Kettle和ETL的基本构成
不多说,直接上干货! 这里,我说的通俗易懂点,好方便大家的理解. ETL解决方案就像业务流程一样,具有输入.输出,以及一个或多个工作环节,处理步骤.同样的,这些步骤也具有输入和输出,并可以执行将一个输 ...
- Windows phone解决GB2312编码问题
环境win8+vse for Windows phone 在网站http://encoding4silverlight.codeplex.com/上点击下载 之后有三个文件big5.bin,DBCSE ...
- Codeforces 982 B. Bus of Characters(模拟一个栈)
解题思路: 排序之后模拟一个栈(也可以用真的栈),时间复杂度o(n). 代码: #include <bits/stdc++.h> using namespace std; typedef ...
- 8年js总结
http://www.cnblogs.com/tylerdonet/p/5543813.html
- mybatis批量插入、批量更新和批量删除
转载 https://www.jianshu.com/p/041bec8ae6d3
- 使用maven插件dockerfile-maven-plugin生成Docker镜像并推送到镜像仓库
1.引入maven插件 <build> <plugins> <plugin> <groupId>com.spotify</groupId> ...
- GET,POST请求
get请求 post请求
- React中的AES加解密请求
引言 在我们使用React开发Web前端的时候,如果是比较大的项目和正常的项目的话,我们必然会用到加解密,之前的文章中提到.NET的一些加解密,那么,这里我就模拟一个例子: 1.后台开发API接口,但 ...