当前位置:网站首页>取石子
取石子
2022-07-21 05:15:00 【龙星尘】
4396.取石子
两个小朋友玩取石子游戏。
第一个小朋友面前有 n1个石子,第二个小朋友面前有 n2 个石子。
两人轮流取自己面前的石子。
第一个小朋友先手,第二个小朋友后手。
第一个小朋友每轮次最多取 k1 个石子,最少取 1 个石子。
第二个小朋友每轮次最多取 k2 个石子,最少取 1个石子。
率先取完自己面前石子的小朋友,视为失败。
请问,两个小朋友都采取最优策略的情况下,谁会获胜?
输入格式
一行,四个整数 n1,n2,k1,k2
输出格式
如果第一个小朋友获胜,则输出 First
,如果第二个小朋友获胜,则输出 Second
。
数据范围
所有测试点满足 1≤n1,n2,k1,k2≤50
输入样例1:
2 2 1 2
输出样例1:
Second
输入样例2:
2 1 1 1
输出样例2:
First
根据题意我们可以知道,要采用最优策略,最优策略是什么呢?就是谁也不让谁,打的最久,要想时间最长不就是一个一个的拿吗?所以k1和k2完全是来误导我们的,k1和k2在程序中不会被用到,只要装个样子输入就对了。
代码:
#include <iostream>
using namespace std;
int main()
{
int n1,n2,k1,k2;
cin>>n1>>n2>>k1>>k2;
while(n1!=0&&n2!=0)
{
n1-=1;
n2-=1;
}
if(n1==0)
cout<<"Second"<<endl;
else if(n2==0)
cout<<"First"<<endl;
}
一个while循环来判断哪个小朋友的石子先变为0,则对面小朋友获胜,是不是很简单,简直是一道送分题。
边栏推荐
- 148. 排序链表
- 3级学业水平测试
- 19. 删除链表的倒数第 N 个结点
- robotframework--浏览器驱动和操作的实现(1)
- The 22 pictures show you in-depth analysis of prefix, infix, suffix expressions and expression evaluation
- What impact does the Internet of things have on the development of enterprises?
- 108. 将有序数组转换为二叉搜索树
- What is PCBA? What is the importance of PCBA testing?
- What are the functions and application industries of testing equipment development?
- What is the gateway? What is the Internet of things gateway?
猜你喜欢
In depth analysis of LinkedList source code
Interview question: what is the difference between clustered index and non clustered index?
05 unittest extension
深入剖析多重背包问题(下篇)
Do you think sub database and sub table are really suitable for your system? Talk about how to select sub databases, sub tables and newsql
03-selenium的自动化测试模型
深入剖析斐波拉契数列
The top three suddenly changed? Unveil the latest ranking of programming languages in July
近10年数据仓库演进之路,以及数据库学习建议
Teach you how to use Charles to grab bags
随机推荐
Deep analysis of fiboracci sequence
Summary of Niuke online question brushing -- top101 must be brushed for interview
Characteristics and differences between PCB and integrated circuit
Liteos connector script (I)
Huawei liteos memory management source code and architecture analysis
Verification code is the natural enemy of automation? See how the great God solved it
When using mysql, please make good use of JSON
RobotFramework(ride)关键字无法使用或关键字为黑色
P/NP/NP完全/NP难
面试官:你的update 更新影响行数做判断了吗?
03-selenium的自动化测试模型
Robotframework -- implementation of browser drive and operation (1)
Qt5 GUI
数据可视化图表插件开发作品大赏(一)
Vs2019+opencv installation and configuration tutorial
深入剖析多重背包问题(上篇)
Pytorch2onnx2Tensorflow的环境准备win10
集合间的映射和集合的势
226. 翻转二叉树
22张图带你深入剖析前缀、中缀、后缀表达式以及表达式求值