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

武大OJ 622. Symmetrical的更多相关文章

  1. 武大OJ 574. K-th smallest

    Description Give you a number S of length n,you can choose a position and remove the number on it.Af ...

  2. 武大OJ 613. Count in Sama’s triangle

    Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...

  3. 武大OJ 612. Catch the sheep

    Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...

  4. 武大OJ 706.Farm

    Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made ...

  5. Online Judge(OJ)搭建(第一版)

    搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...

  6. [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ

    前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...

  7. oj Rapid Typing

    import bs4 import requests import urllib2 import time import base64 session=requests.Session() respo ...

  8. 在线OJ实用技巧(转载)

    1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long long或__int64型(两个下 ...

  9. OJ生成器(一)制作Online Judge前的准备和策划

    我这校区新的微机老师斗志昂扬,准备让我们这学校萎靡的信息技术竞赛重振雄风.然后有一次我半开玩笑地说建一个自己的OJ吧,老师也就鼓励我去做了. 开什么玩笑……!我可是马上要参加NOIP的人! 于是老师说 ...

随机推荐

  1. 贪心 FZU 2013 A short problem

    题目传送门 /* 题意:取长度不小于m的序列使得和最大 贪心:先来一个前缀和,只要长度不小于m,从m开始,更新起点k最小值和ans最大值 */ #include <cstdio> #inc ...

  2. 莫队算法/二分查找 FZU 2072 Count

    题目传送门 题意:问区间内x的出现的次数分析:莫队算法:用一个cnt记录x的次数就可以了.还有二分查找的方法 代码: #include <cstdio> #include <algo ...

  3. 9i 和 11 g 区别

    9i 和 11 g 区别 9i 不支持 2/4/8G,只支持 2000/4000/8000 M的

  4. 309 Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期

    Say you have an array for which the ith element is the price of a given stock on day i.Design an alg ...

  5. SQL数据库语言基础

    表的创建: 1.创建列(字段):列名+类型 2.设置主键列:能够唯一标识一条数据 3.设置唯一:内容不能重复 4.外键关系: 一张表(从表)其中的某列引用自另外一张表(主表)中的主键列 设计表: 数据 ...

  6. 61配置nanopim1plus的HDMI为1080p输出

    61配置nanopim1plus的HDMI为1080p输出 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2018/4/4 10:21 版本:V1.1 开 ...

  7. mongo 3.4分片集群系列之八:分片管理

    这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...

  8. Apache JServ protocol服务 怎么关闭?

      Apache JServ protocol  =  AJP 解决方案:修改tomcat 的service.xml配置文件 将 <Connector port="8009" ...

  9. 并发编程学习笔记(11)----FutureTask的使用及实现

    1. Future的使用 Future模式解决的问题是.在实际的运用场景中,可能某一个任务执行起来非常耗时,如果我们线程一直等着该任务执行完成再去执行其他的代码,就会损耗很大的性能,而Future接口 ...

  10. WINVER WIN32 WINNT

    WINVER 和 _WIN32_WINNT 请在WINDOWS.H前定义 从 Visual C++ 2008 开始,Visual C++ 不支持面向 Windows 95.Windows 98.Win ...