HDU5340 Three Palindromes
Three Palindromes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1680 Accepted Submission(s):
596
http://acm.hdu.edu.cn/showproblem.php?pid=5340
Problem Description
palindromes?
Input
which denotes the number of test cases.
For each test case , there is an
single line contains a string S which only consist of lowercase English
letters.1≤|s|≤20000
Output
line.
Sample Input
Sample Output
题目大意:
#include<iostream>//把注释去掉,上面的加注释将是另一种表示方法
#include<cstdio>
#include<cstring>
using namespace std;
int Case,rad[*],q1[*],q2[*];
char s[],c[*];
void manacher(){
int len=strlen(s+);
for(int i=len;i>=;i--){
c[i*]=s[i];
c[i*+]='#';
}c[]='$';
int k=;
for(int i=;i<=len*;i++){
if(rad[k]+k>i)rad[i]=min(k+rad[k]-i,rad[*k-i]);
else rad[i]=;
while(c[i-rad[i]]==c[i+rad[i]])rad[i]++;
if(i+rad[i]>k+rad[k])k=i;
}
}
int main(){
scanf("%d",&Case);
while(Case--){
int l=,r=;
memset(rad,,sizeof(rad));
memset(q1,,sizeof(q1));
memset(q2,,sizeof(q2));
scanf("%s",s+);
int n=strlen(s+);n=n*+;
manacher();
for(int i=;i<=n;i++){
if(i==rad[i]&&i!=)q1[++l]=i;
if(n+-i==rad[i]&&i!=n)q2[++r]=i;
/*if(i==rad[i]&&i!=1)q1[++l]=rad[i];
if(n+1-i==rad[i]&&i!=n)q2[++r]=rad[i];*/
}
bool flag=;int t1,t2;
for(int i=;i<=l;i++){
if(flag==)break;
for(int j=;j<=r;j++){
t1=q1[i]*;t2=n-*(n-q2[j])-;
/*t1=q1[i]*2;t2=n+1-q2[j]*2;*/
if(t1>t2)continue;
if(t2-t1==)continue;
int mid=(t1+t2)>>;
if(rad[mid]*->=t2-t1+){flag=;break;}
}
}
if(flag==){printf("Yes\n");}
else printf("No\n");
}
}
HDU5340 Three Palindromes的更多相关文章
- hdu5340—Three Palindromes—(Manacher算法)——回文子串
Three Palindromes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU-5340 Three Palindromes(字符串哈希)
http://acm.hdu.edu.cn/showproblem.php?pid=5340 orz到了新的字符串hash姿势 #include<cstdio>#include<cs ...
- hdu5340 Three Palindromes(manacher算法)
题目描写叙述: 推断能否将字符串S分成三段非空回文串. 解题思路: 源码: #include <cstdio> #include <algorithm> #define MAX ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- hdu 1318 Palindromes
Palindromes Time Limit:3000MS Memory Limit:0KB 64bit ...
- dp --- Codeforces 245H :Queries for Number of Palindromes
Queries for Number of Palindromes Problem's Link: http://codeforces.com/problemset/problem/245/H M ...
- Dual Palindromes
Dual PalindromesMario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same ...
- ytu 1940:Palindromes _easy version(水题)
Palindromes _easy version Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 47 Solved: 27[Submit][Statu ...
- 回文串+回溯法 URAL 1635 Mnemonics and Palindromes
题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...
随机推荐
- ubuntu安装opencv(自己编译)
如果只需要python的,只需pip install opencv-python,然后apt-get一下下面第一点的东东. 1/ sudo apt-get install build-essentia ...
- 【ansible】ansible部署方式以及部署包
最近研究ansible的使用,在使用pip安装的时候遇到很多奇怪的问题,为此采用了手动安装的方式,并编写了一键安装脚本. ansible要求机器必须安装python2.6以上版本,可以通过一下命令查看 ...
- HTML——列表的相关知识
核心知识点: 1.无序列表: ul>li 2.有序列表:ol>li 3.标题列表:dl(标签)>dt(标题)>dd(选项) 4.表格:table>thead(>tr ...
- HTML5/CSS3简易版俄罗斯方块游戏
在线演示 本地下载
- BZOJ3262 陌上花开 —— 三维偏序 CDQ分治
题目链接:https://vjudge.net/problem/HYSBZ-3262 3262: 陌上花开 Time Limit: 20 Sec Memory Limit: 256 MBSubmit ...
- 基于KD-Tree的最近邻搜索
目标:查询目标点附近的10个最近邻邻居. load fisheriris x = meas(:,:); figure(); g1=gscatter(x(:,),x(:,),species); %spe ...
- 前端多媒体(1)——获取摄像头&麦克风
捕获视频/音频 PPT地址 长久以来,音频/视频捕获都是网络开发中的"圣杯".多年来,我们总是依赖于浏览器插件(Flash 或 Silverlight)实现这一点. 依靠 WebR ...
- dead reckoning variation
Targeting A target is a structure of information that describes the state, and change of state, of a ...
- MySQL_杭州拱墅区、西湖区近9-11月销售过的产品_20161125
需求:杭州拱墅区.西湖区近9-11月销售过的产品 这个SQL如果对数据表熟悉的话可以一步到位,为了看的更清楚,时间间隔在3个月产品数量也不是很多,采取先找明细再进行汇总. 一.第一种写法 分步骤的写S ...
- Ubuntu 重启命令
重启命令: 1.直接reboot 2.shutdown -r now 这两种都是立刻重启 3.shutdown -r 大概30秒后会重启 关机命令:1.halt 立刻关机2.poweroff 立刻 ...