武大OJ 622. Symmetrical
Description
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的更多相关文章
- 武大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 ...
- 武大OJ 613. Count in Sama’s triangle
Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...
- 武大OJ 612. Catch the sheep
Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...
- 武大OJ 706.Farm
Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made ...
- Online Judge(OJ)搭建(第一版)
搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...
- [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ
前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...
- oj Rapid Typing
import bs4 import requests import urllib2 import time import base64 session=requests.Session() respo ...
- 在线OJ实用技巧(转载)
1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long long或__int64型(两个下 ...
- OJ生成器(一)制作Online Judge前的准备和策划
我这校区新的微机老师斗志昂扬,准备让我们这学校萎靡的信息技术竞赛重振雄风.然后有一次我半开玩笑地说建一个自己的OJ吧,老师也就鼓励我去做了. 开什么玩笑……!我可是马上要参加NOIP的人! 于是老师说 ...
随机推荐
- markdown 常用语法总结 - 个人版
这里并不是要总结所有的 markdown 语法,只是总结笔者自己撰写博客时常用的一些 markdown 语法. 1 图片设置 1.1 设置图片位置 利用markdown在编写文档时插入图片是默认靠左, ...
- [Usaco2018 Open]Disruption
Description Farmer John自豪于他所经营的交通发达的的农场.这个农场是由N块牧场(2≤N≤50,000)组成的,N-1条双向道路将它们连接起来,每一条道路的都为一单位长度.Farm ...
- Poj 3694 Network (连通图缩点+LCA+并查集)
题目链接: Poj 3694 Network 题目描述: 给出一个无向连通图,加入一系列边指定的后,问还剩下多少个桥? 解题思路: 先求出图的双连通分支,然后缩点重新建图,加入一个指定的边后,求出这条 ...
- FFT学习及简单应用(一点点详细)
什么是FFT 既然打开了这篇博客,大家肯定都已经对FFT(Fast Fourier Transformation)有一点点了解了吧 FFT即为快速傅里叶变换,可以快速求卷积(当然不止这一些应用,但是我 ...
- redis学习-sds数据类型
今天开始了redis的学习,本来想直接从源码看起的,不过看到有篇对redis介绍的基础教程 <Redis 设计与实现(第一版)> 于是决定从这个开始入门. 1.数据类型定义 typedef ...
- css3 动画 vs js 动画
之前被问到过,css3 动画与 js 动画孰优孰劣,脑袋的第一反应就是性能上肯定 css3 动画会好很多,但别人说不对,我就在想,不对?难道还有别的原因吗?答案是肯定的.先来看看二者实现动画的原理吧. ...
- 一次“MySQL server has gone away”故障及其解决
1,问题现象 某次测试发现,程序失去响应.由于程序集成了EurekaLog组件,弹出了错误框.查看其给出的Call Stack信息,发现没有发生线程死锁(DeadLock=0;),问题在于 Wait ...
- jquery onclick 问题
var str = ''; for(var i = 0;i<data.list.length;i++){ str += "<tr><td>" + (i ...
- 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误" One of the configured ...
- java.net.MalformedURLException: no protocol: www.baidu.com
URL url = new URL("www.baidu.com");改为 URL url = new URL("http://www.baidu.com");