Codeforces--513A--Game

73 篇文章 0 订阅

题目描述:
Two players play a simple game. Each player is provided with a box with balls. First player’s box contains exactly n1 balls and second player’s box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can’t make a move loses. Your task is to determine who wins if both players play optimally.
输入描述:
The first line contains four integers n1, n2, k1, k2. All numbers in the input are from 1 to 50.
This problem doesn’t have subproblems. You will get 3 points for the correct submission.
输出描述:
Output “First” if the first player wins and “Second” otherwise.
输入:
2 2 1 2
2 1 1 1
输出:
Second
First
题意:
两个人有n1,n2个球,然后分别最多拿出 k1,k2个球,然后扔掉,谁先拿完谁输。
题解
简单博弈,假设两人足够聪明,每次都只丢一个,那么,谁的球多,谁就能赢。如果一样,先手输
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
    int n,m,k1,k2;
    while(scanf("%d%d%d%d",&n,&m,&k1,&k2)!=EOF){
        if(n > m) printf("First\n");
        else printf("Second\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值