Codeforces Beta Round #7--D. Palindrome Degree(Manacer)
题目:http://blog.csdn.net/winddreams/article/details/44218961
求出每一个点为中心的最长字符串,推断该串是不是从开头的回文串。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
int p[12000000] , dp[6000000];
char s[12000000] , str[12000000] ;
int init() {
int i , j , l ;
l = strlen(s) ;
str[0] = '&' ;
for(i = 0 , j = 1 ; i < l ; i++) {
str[j++] = '#' ;
str[j++] = s[i] ;
}
str[j++] = '#' ;
str[j] = '\0' ;
return j ;
}
void Manacer(int l) {
int i , max1 = 0 , id ;
p[0] = 0 ;
for(i = 1 ; i < l ; i++) {
if( max1 > i )
p[i] = min(p[2*id-i],max1-i) ;
else
p[i] = 1 ;
while( str[ i-p[i] ] == str[ i+p[i] ] )
p[i]++ ;
if( p[i]+i > max1 ) {
max1 = p[i] + i ;
id = i ;
}
//printf("%d ", p[i]) ;
}
//printf("\n") ;
}
int main() {
int i , j , l , x , ans = 0 ;
scanf("%s", s) ;
l = init() ;
Manacer(l) ;
memset(dp,0,sizeof(dp)) ;
for(i = 2 ; i < l/2+1 ; i++) {
if( i%2 == 1 && i/2 == (p[i]-1)/2 ) {
x = p[i] - 1 ;
dp[x] = dp[x/2] + 1 ;
ans += dp[x] ;
}
else if( i%2 == 0 && p[i] == i ) {
x = p[i] - 1 ;
dp[x] = dp[x/2] + 1 ;
ans += dp[x] ;
}
}
printf("%d\n", ans) ;
}
Codeforces Beta Round #7--D. Palindrome Degree(Manacer)的更多相关文章
- Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp
题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...
- Codeforces Beta Round #7 D. Palindrome Degree hash
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...
- Codeforces Beta Round #7 D. Palindrome Degree —— 字符串哈希
题目链接:http://codeforces.com/contest/7/problem/D D. Palindrome Degree time limit per test 1 second mem ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- Codeforces Beta Round #51 D. Beautiful numbers(数位dp)
题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...
- Codeforces Beta Round #88 C. Cycle —— DFS(找环)
题目链接:http://codeforces.com/problemset/problem/117/C C. Cycle time limit per test 2.5 seconds memory ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Global Round 11 B. Chess Cheater(贪心)
题目链接:https://codeforces.com/contest/1427/problem/B 题意 给出一个长为 \(n\) 由 W, L 组成的字符串,如果一个 W 左侧为 W,则它提供 2 ...
- Codeforces Global Round 8 C. Even Picture(构造)
题目链接:https://codeforces.com/contest/1368/problem/C 题意 构造一个只含有灰.白块的网格,要求: 所有灰块为一个连通块 每个灰块与偶数个灰块相邻 恰有 ...
随机推荐
- Spring配置文件头及xsd文件版本
最初Spring配置文件的头部声明如下: Xml代码 <?xml version="1.0" encoding="UTF-8"?> <!D ...
- 删除GitHub上项目中的某个文件
原文地址 https://www.jianshu.com/p/242412b43ca5 1.首先在本地中更新有该项目的最新包 即确保本地项目和git上的项目内容保持同步(git pull拉取项目代码) ...
- eclipse设置jvm
设置参数: -Xverify:none -Xms512m -Xmx512m -Xmn128m -XX:PermSize=96m -XX:MaxPermSize=96m -XX:+UseConcMark ...
- 单机/伪分布式Hadoop2.4.1安装文档 2014-07-08 21:16 2275人阅读 评论(0) 收藏
转载自官方文档,最新版请见:http://hadoop.apache.org/docs/r2.4.1/hadoop-project-dist/hadoop-common/SingleCluster.h ...
- php实现用短路求值原理求1+2+3+...+n(短路求值是什么)(仔细分析题干)
php实现用短路求值原理求1+2+3+...+n(短路求值是什么)(仔细分析题干) 一.总结 1.仔细分析题干,找出要点:该递归还是得递归啊 2.短路求值原理:&&就是逻辑与,逻辑与有 ...
- teamview huawei
https://apkpure.com/add-on-huawei/com.teamviewer.quicksupport.addon.huawei 4.0/5 ( 5 Discussions ) ...
- USB 3.0规范中译本 第7章 链路层
本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 链路层具有维持链路连接性的责任,从而确保在两个链路伙伴之间的成功数据传输.基于包(packets)和链路命令 ...
- jsvc 启动java 在linux下的实现原理
http://blog.csdn.net/raintungli/article/details/8265009 JSVC:http://commons.apache.org/proper/common ...
- MySQL key分区(五)
具体描写叙述总结请看MySQL分区(一) 样例:该样例为本人个人学习总结分享->具体说明-->有问题欢迎前来交流
- 百度echart--Uncaught Error: Component series.wordCloud not exists. Load it first.
百度echart--Uncaught Error: Component series.wordCloud not exists. Load it first. 一.总结 一句话总结:关注报的错.可以通 ...