codeforces_rockethon2015 A. Game,codeforces

來源:互聯網
上載者:User

codeforces_rockethon2015 A. Game,codeforces
time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

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

Output "First" if the first player wins and "Second" otherwise.

Sample test(s)input
2 2 1 2
output
Second
input
2 1 1 1
output
First
Note

Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.


解題分析:

這道題看著是噁心,其實就是一道簡單的博弈論問題。具體什麼是博弈論請自行補習。

這裡選擇就是在n1, n2, 中分別拿出k1, k2個球。如果輪到誰拿的時候沒有球了。那麼就輸了。

我覺得這裡是想告訴我們,要給自己留後路(這句話忽略吧)


代碼:

相信都會看懂的。


#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
while(1)
{
n1 -= k1;
n2 -= k2;
if(n1 > n2)
{
cout<<"Second"<<endl;
break;
}
else
{
cout<<"First"<<endl;
break;
}
}
return 0;
}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.