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开始)最少需要划分的数 ...
随机推荐
- 04-树7 二叉搜索树的操作集(30 point(s)) 【Tree】
04-树7 二叉搜索树的操作集(30 point(s)) 本题要求实现给定二叉搜索树的5种常用操作. 函数接口定义: BinTree Insert( BinTree BST, ElementType ...
- Java多线程系列 基础篇04 线程中断
1. 中断线程 中断可以理解为线程的一个标志位属性,它表示一个运行中的线程是否被其他线程进行了中断操作,其他线程通过调用该线程的interrupt()方法对其进行中断操作,线程通过检查自身是否被中断来 ...
- JVM 什么时候会full gc
除直接调用System.gc外,触发Full GC执行的情况有如下四种.1. 旧生代空间不足旧生代空间只有在新生代对象转入及创建为大对象.大数组时才会出现不足的现象,当执行Full GC后空间仍然不足 ...
- 使用git连接到Github
直奔主题,使用git连接到Github步骤如下: 1. 安装git yum install git 或者 sudo get-apt install git git-core 2. 全局配置 git c ...
- 《avascript 高级程序设计(第三版)》 ---第三章 基本概念2
1.乘性操作符: 1)*法操作法: Infinity * 0 = NaN Infinity * 非零 = Infinity 或 - Infinity 2)/法操作符: Infinity / In ...
- JAVA- String类练习
JAVA- String类练习 需求1:去除字符串两边空格的函数,写一个自己的trim(); public class TestTrim { public static void main(Strin ...
- 深入理解JVM - Java内存模型与线程 - 第十二章
Java内存模型 主内存与工作内存 Java内存模型主要目标:定义程序中各个变量的访问规则,即在虚拟机中将变量存储到内存和从内存中取出变量这样的底层细节.此处的变量(Variable)与Java编程中 ...
- CI公用模型
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * SEO管理系统 -- 公用模型 ...
- MySQL当月汇总 及负毛利汇总_20161027
#当月汇总 及负毛利汇总 SELECT e.ID,e.city AS 城市 ,f.当月销售总额,f.当月成本总额,f.当月毛利总额,f.当月优惠券总额,f.当月赠品总额,f.当月毛利总额-f.当月优惠 ...
- 【Python】python2.7 安装配置OpenCV2
环境:Ubuntu16.04 anaconda Python2.7 opencv2.4.13 安装opencv后 import cv2 遇到错误信息: No module named cv2 安装op ...