武大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的人! 于是老师说 ...
随机推荐
- dubbo与zookeeper学习中的问题
环境: spring5.1.5 dubbo 2.6.2 异常信息: java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy at ...
- 微信开发解决if...else..的臃肿
开发中难以避免if...else (switch case ),大量的if...else 让代码可读性低...难以维护 无论是接手别人的代码还是自己写的代码,因为开发周期短可能就往往忽略了这一点. 久 ...
- git 删除分支如何恢复
强制删除了一个分支而后又想重新使用这个分支,该怎么找回该分支上的代码呢? 一:问题描述: 今天师父说上线几个功能,让我把开发的分支推送到远程.当打开git就傻眼了,之前开发好的分支被我删除了,就连推送 ...
- Android学习笔记(四) JAVA基础知识回顾
一.接口 1)接口中定义的方法都是public权限,并且默认为public,而不是default. 2)接口的实现(implements)是特殊的继承,类似于父类子类的关系,可以向上转型(非常重要). ...
- IBatis的分页研究
IBatis的分页研究 博客分类: Ibatis学习 摘自: http://cpu.iteye.com/blog/311395 yangtingkun Oracle分页查询语句 ibaits. ...
- 北大ACM(POJ1020-Anniversary Cake)
Question:http://poj.org/problem?id=1020 问题点:DFS. Memory: 260K Time: 47MS Language: C++ Result: Accep ...
- DIV自动居中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- CentOS上oracle 11g R2数据库安装折腾记
1.虚拟机上centos镜像的获取.这里推荐网易镜像站中的CentOS7版本(其他开源镜像站亦可).这里给出链接: http://mirrors.163.com/centos/7.3.1611/iso ...
- 动态设置缩放比例和html字体大小
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...
- oracle_backup
#!/bin/bash DAYS=`date +"%Y%m%d"` . /home/oracle/.bash_profile # /home/opt/oracle/11g/bin/ ...