B. Little Girl and Game

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值