B. Little Girl and Game

來源:互聯網
上載者:User
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The Little Girl loves problems on games very much. Here's one of them.

Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules:

  • The players move in turns; In one move the player can remove an arbitrary letter from string s.
  • If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that
    reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc"
    isn't.

Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.

Input

The input contains a single line, containing string s (1 ≤ |s|  ≤  103).
String s consists of lowercase English letters.

Output

In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second".
Print the words without the quotes.

Sample test(s)input
aba
output
First
input
abca
output
Second

解題說明:此題的大意是兩個人進行比賽,每個人都可以在刪去某個字母之前對字串進行任意編排看看是否存在迴文的情況,如果存在該情況則此人獲勝,否則就刪去一個字串後輪到另一個人進行判斷,問最終誰能贏得比賽。求解的思路是判斷字串中存在26個字母中的每個字母出現的個數,統計每一個字母的個數為奇數的字母總數,如果為奇數,則第一個人勝,否則為第二個勝【注意要單獨考慮上來就能組成迴文字串的情況,其實取值為0】。

下面來說說為什麼判斷奇數情況下第一個人肯定會贏,記這個數為m

當m=1或者m=0 是first贏

當m=k k為奇數時,first希望到達m=1或者0的情況,對於First來說,他只需要將任意一個奇數個的字元去掉就可以了,這時候,如果m!=0,Second是一定不能馬上贏的,因為Second只能去掉一個字元,這時候,無論Second去掉哪個字元,到First的時候,面臨的都是m%2 == 1的情況,但是字元數目會減少,這樣的話,一定是First先面對m== 0 或者m ==1 的情況,所以First一定贏

與此同理可以證明 m為非0偶數時second必勝

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int i,a[26]={0};char s[1002];int count;scanf("%s",&s);for(i=0;s[i]!='\0';i++){a[s[i]-'a']++;}count=0;for(i=0;i<26;i++){if(a[i]%2==1){count++;}}if(count==0||count%2==1){printf("First\n");}else{printf("Second\n");}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.