题目: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)的更多相关文章

  1. Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp

    题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...

  2. Codeforces Beta Round #7 D. Palindrome Degree hash

    D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...

  3. Codeforces Beta Round #7 D. Palindrome Degree —— 字符串哈希

    题目链接:http://codeforces.com/contest/7/problem/D D. Palindrome Degree time limit per test 1 second mem ...

  4. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  5. Codeforces Beta Round #51 D. Beautiful numbers(数位dp)

    题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...

  6. Codeforces Beta Round #88 C. Cycle —— DFS(找环)

    题目链接:http://codeforces.com/problemset/problem/117/C C. Cycle time limit per test 2.5 seconds memory ...

  7. 『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 ...

  8. Codeforces Global Round 11 B. Chess Cheater(贪心)

    题目链接:https://codeforces.com/contest/1427/problem/B 题意 给出一个长为 \(n\) 由 W, L 组成的字符串,如果一个 W 左侧为 W,则它提供 2 ...

  9. Codeforces Global Round 8 C. Even Picture(构造)

    题目链接:https://codeforces.com/contest/1368/problem/C 题意 构造一个只含有灰.白块的网格,要求: 所有灰块为一个连通块 每个灰块与偶数个灰块相邻 恰有 ...

随机推荐

  1. P2P网贷第三方托管模式存在5大缺陷,托管机构才是最大赢家

    1.注册开户需要2次,用户体验很差劲儿.   理财人和借款人,首先在平台注册,然后还要在第三方托管账户注册.   很多类似的地方,用户体验非常差劲.   比如,密码4个.   平台:登录密码.交易密码 ...

  2. ASIC DC综合的理解

    ASIC DC综合的理解 DC综合流程 输入设计文件+指定的工艺库文件+约束文件 经过DC的综合,输出满足期望的门级网表及综合报告 输入输出数据 输入文件:设计文件(verilog等).工艺库(db) ...

  3. mha && 脚本拉起

    ip分布:  vip 192.168.238.222 mha_manager 192.168.238.131 监控服务器 master 192.168.238.128 主库GTID复制模式 slave ...

  4. 关于.c和.h 和定义变量的问题

    最初调试的时候是因为有个错误在wavplay.h文件中 于是我跳到了recorderl.h中:从图中看到引用了main.h 出现这个问题的具体原因还是不太清楚: 不过我任务是因为: wavplay.h ...

  5. angular表单经验分享

    原文 https://www.jianshu.com/p/af359bd04f32 大纲 1.表单的名字不可以和传入的值的名字相同 2.在模板驱动表单的时候要使用angular表单的验证功能,需要将n ...

  6. iOS开发之Quartz2D 五:UIKIT 绘图演练,画文字,画图片

    #import "DrawView.h" @implementation DrawView -(void)awakeFromNib { // //画图片 // UIImage *i ...

  7. JasperReport html 导出

    In my last blog post I discussed about Generating jasper reports in different formats using json fil ...

  8. Thinking in UML 学习笔记(四)——UML核心视图之活动图

    在UML中活动图的本质就是流程图,它描述了为了完成某一个目标需要做的活动以及这些互动的执行顺序.UML中有两个层面的活动图,一种用于描述用例场景,另一种用于描述对象交互. 活动图只是我们用来描述业务目 ...

  9. 诊断并解决CentOS SSH连接慢的方法

    诊断并解决CentOS SSH连接慢的方法: http://os.51cto.com/art/201507/484743.htm

  10. Redis的增删改查、持久化你会了吗

    原文:Redis的增删改查.持久化你会了吗 Redis是用C语言实现的,一般来说C语言实现的程序"距离"操作系统更近,执行速度相对会更快. Redis使用了单线程架构,预防了多线程 ...