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;}