1. 程式人生 > >6486: An Ordinary Game(規律)

6486: An Ordinary Game(規律)

per lap 題目 IE with EDA led view form

題目描述

There is a string s of length 3 or greater. No two neighboring characters in s are equal.
Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:
Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.
The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.

Constraints
3≤|s|≤105
s consists of lowercase English letters.
No two neighboring characters in s are equal.

輸入

The input is given from Standard Input in the following format:
s

輸出

If Takahashi will win, print First. If Aoki will win, print Second.

樣例輸入

aba

樣例輸出

Second

提示

Takahashi, who goes first, cannot perform the operation, since removal of the b, which is the only character not at either ends of s, would result in s becoming aa, with two as neighboring.

很很簡單的一個找規律題,但是卡了好久。

頭尾相同的時候,最後肯定是剩下奇數個字母的,比如ababa。那麽如果位數是奇數那麽中間肯定進行了偶數次操作,反正就是奇數次。

頭尾不同的話,最後剩下偶數個,如果位數為奇數就操作了奇數次,否則偶數次。

偶數次操作那麽第一個人就無法操作就輸,奇數次操作第二個人無法操作即輸。

技術分享圖片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     string s;
 7     cin>>s;
 8     int len = s.length();
9 if(s[0] == s[len-1]) 10 if(len&1)printf("Second\n"); 11 else printf("First\n"); 12 else 13 if(len&1)printf("First\n"); 14 else printf("Second\n"); 15 }
View Code

6486: An Ordinary Game(規律)