博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
6486: An Ordinary Game(规律)
阅读量:4884 次
发布时间:2019-06-11

本文共 1550 字,大约阅读时间需要 5 分钟。

题目描述

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
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 else13 if(len&1)printf("First\n");14 else printf("Second\n");15 }
View Code

 

转载于:https://www.cnblogs.com/iwannabe/p/9107544.html

你可能感兴趣的文章
异常处理与调试6 - 零基础入门学习Delphi55(完)
查看>>
if语句三种形式
查看>>
正则表达式之字符串验证
查看>>
codeblocks如何支持_tmain?可移植代码的编码推荐
查看>>
省市联动 填坑
查看>>
canvas写的一个小时钟demo
查看>>
原来今天是冬至
查看>>
又混了一天班
查看>>
九度oj 1006
查看>>
HDU6400-2018ACM暑假多校联合训练1004-Parentheses Matrix-构造
查看>>
最短路问题专题
查看>>
《Redis复制与可扩展集群搭建》看后感
查看>>
Jquery Mobile总结
查看>>
223. Rectangle Area
查看>>
spring boot + velocity中文乱码解决方式
查看>>
读罢泪两行,人生成长必须面对的10个残酷事实
查看>>
ASP 32位程序运行与64位问题:ADODB.Connection 错误 '800a0ea9' 未指定提供程序,也没有指派的默认提供程序。...
查看>>
xcode-git笔记
查看>>
TCP和UDP的优缺点及区别
查看>>
MATLAB消除曲线毛刺Outlier Detection and Removal [hampel]
查看>>