Description

         Cyy likes something symmetrical, and Han Move likes something circular. Han Move gave you a circular string whose length is N, i.e. the i-th character of the string is the neighbor of the ( (i-1) mod N )-th character and ( (i+1) mod N )-th character.
         As Cyy likes something symmetrical, you want to find out whether this string can be symmetrical. There’s an operation for you to make the string symmetrical. This operation is called “disconnect”. You can use “disconnect” only once to break the link between any two neighbor characters, making the circular string into a linear string. If you can use “disconnect” to make this string into a palindrome, this string can be considered to be symmetrical.

Please tell Cyy whether this circular string is symmetrical.

Input

The input file consists of multiple test cases.
For each test case, there’s only a string in a line to represent the circular string. The string only consists of lowercase characters. ( 1 <= N <= 65536 )
It’s guaranteed that the sum of N is not larger than 1000000.

Output

For each test case, output “Yes” in a line if the circular string is symmetrical, output “No” otherwise.

Sample Input

aaaaaa
abcde
ababab
aaaaba
aabbaa

Sample Output

Yes
No
No
No
Yes

一句话题意:循环字符串能否断开形成回文串
循环的东西,很明显要直接复制一遍
回文串,很明显manacher

如果原串长度len为奇数,则找到的回文数长度m必须>=len且m为奇数

如果原串长度len为偶数,则找到的回文数长度m必须>=len且m为偶数

一开始总是超时,一直以为是判断输入结束不对,后来才发现是用了string,每次都用string生成!#a#b..,很耗时!

 #include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std; int p[];
bool manacher(char* s,int len){
int length=;
int maxRight=;
int mid=;
int l=strlen(s);
for(int i=;i<l;++i)
{
if(i<maxRight)
p[i]=min(p[*mid-i],maxRight-i);
else p[i]=; while(s[i-p[i]]==s[i+p[i]]) p[i]++; if(p[i]+i>maxRight)
{
maxRight=p[i]+i;
mid=i;
}
length=p[i]-;
if(len%==)
{
if(!(length<len||length%==))
return true;
}
if(len%==)
{
if(!(length<len||length%==))
return true;
}
}
return false; } int main()
{
int len;
char s[]; while(~scanf("%s",&s))
{
len=strlen(s);
for(int i=len;i>=;--i)
s[i+len]=s[i];
// cout<<s<<endl;
for(int i=*len;i>=;--i)
{
s[*i+]=s[i];
s[*i+]='#';
} s[]='!';
// cout<<s<<endl; if(manacher(s,len)==true)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} }
												

最新文章

  1. 关于C3翘边阴影的demo
  2. Android 光线传感器的调用
  3. 打开mysql时,提示 1040,Too many connections
  4. SharePoint如何关掉mysite. how to disable mysite creation
  5. 深入JVM-垃圾收集器常用的GC参数
  6. maven学习笔记(定制一个Web项目)
  7. 安装WINCC6.0的步骤
  8. windows下端口被占用的解决方法
  9. CSS选择器大汇总
  10. 如何成为一名优秀的web前端工程师
  11. .NET Core WebApi中实现多态数据绑定
  12. bash变量详解
  13. Codeforces 822D My pretty girl Noora - 线性筛 - 动态规划
  14. 使用httpClient模拟http请求
  15. Ajax实例OR技术原理 转自 (http://blog.csdn.net/evankaka )
  16. JavaScript基础语法及数组相关方法(1)
  17. python实现并查集
  18. 【一些简单的jQuery选择器】
  19. elasticsearch删除索引报错【原】
  20. 《利用Python进行数据分析》笔记---第2章--MovieLens 1M数据集

热门文章

  1. 记一次java应用cpu利用率过高调试经历
  2. css边框样式、边框配色、边框阴影、边框圆角、图片边框
  3. Django--4、认证系统
  4. React Native组件的结构和生命周期
  5. PHPStorm+XDebug进行调试
  6. SpringBoot+Mybatis 自动创建数据表(适用mysql)
  7. 10.5 集合ArrayList 和 io流
  8. getBlockTable delete pline
  9. CAD实现文档坐标到视区坐标的转换(com接口Delphi语言)
  10. elk 6.3.2 搭建