题目:http://blog.csdn.net/winddreams/article/details/44218961

求出每一个点为中心的最长字符串,推断该串是不是从开头的回文串。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std ;
  5. int p[12000000] , dp[6000000];
  6. char s[12000000] , str[12000000] ;
  7. int init() {
  8. int i , j , l ;
  9. l = strlen(s) ;
  10. str[0] = '&' ;
  11. for(i = 0 , j = 1 ; i < l ; i++) {
  12. str[j++] = '#' ;
  13. str[j++] = s[i] ;
  14. }
  15. str[j++] = '#' ;
  16. str[j] = '\0' ;
  17. return j ;
  18. }
  19. void Manacer(int l) {
  20. int i , max1 = 0 , id ;
  21. p[0] = 0 ;
  22. for(i = 1 ; i < l ; i++) {
  23. if( max1 > i )
  24. p[i] = min(p[2*id-i],max1-i) ;
  25. else
  26. p[i] = 1 ;
  27. while( str[ i-p[i] ] == str[ i+p[i] ] )
  28. p[i]++ ;
  29. if( p[i]+i > max1 ) {
  30. max1 = p[i] + i ;
  31. id = i ;
  32. }
  33. //printf("%d ", p[i]) ;
  34. }
  35. //printf("\n") ;
  36. }
  37. int main() {
  38. int i , j , l , x , ans = 0 ;
  39. scanf("%s", s) ;
  40. l = init() ;
  41. Manacer(l) ;
  42. memset(dp,0,sizeof(dp)) ;
  43. for(i = 2 ; i < l/2+1 ; i++) {
  44. if( i%2 == 1 && i/2 == (p[i]-1)/2 ) {
  45. x = p[i] - 1 ;
  46. dp[x] = dp[x/2] + 1 ;
  47. ans += dp[x] ;
  48. }
  49. else if( i%2 == 0 && p[i] == i ) {
  50. x = p[i] - 1 ;
  51. dp[x] = dp[x/2] + 1 ;
  52. ans += dp[x] ;
  53. }
  54. }
  55. printf("%d\n", ans) ;
  56. }

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. S​D​I​与​A​S​I 接口具体解释介绍

    分量编码 在对彩色电视信号进行数字化处理和传输是.一种经常使用的方式是分别对其3个分量(Y,R-Y.B-Y)进行数字化编码.这就是分量分量编码.另外还有全信号编码,全信号编码是对彩色全电视信号直接进行 ...

  2. AndroidAnnotations使用说明书—AndroidAnnotations是怎样工作的?

    AndroidAnnotations的工作方式非常easy.它使用标准的java注入处理工具,自己主动加入了一个额外的编译步骤来生成源码. 源代码是什么?每个增强的类,比方每个用@EActivity注 ...

  3. 从源码角度实现一个自己的Promise

    原文链接:https://geniuspeng.github.io/2017/12/14/my-promise/ 关于Promise的概念以及意义就不在这里介绍了,最近看到了一些实现Promise的核 ...

  4. Spring的事务管理和数据库事务相关知识

    1 初步理解 理解事务之前,先讲一个你日常生活中最常干的事:取钱.         比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱. ...

  5. [内核编程] 4.5 HOOK分发函数

    4.5 HOOK分发函数 本节开始深入的探讨键盘的过滤与反过滤.有趣的是,无论是过滤还是反过 滤,其原理都是进行过滤.取胜的关键在于:谁将第一个得到信息. 黑客可能会通过修改一个已经存在的驱动对象(比 ...

  6. Django之分页显示文章

    1.项目:http://www.cnblogs.com/jasonhaven/p/7493422.html 2.任务描述:页面分页显示文章 3.源代码 后台: from django.core.pag ...

  7. 【b602】金明的预算方案

    Time Limit: 1 second Memory Limit: 50 MB [问题描述] 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈 ...

  8. hadoop集群ambari搭建(1)之ambari-server安装

    Apache Ambari是一种基于Web的工具,支持Apache Hadoop集群的供应.管理和监控. Ambari眼下已支持大多数Hadoop组件,包含HDFS.MapReduce.Hive.Pi ...

  9. 机器学习: Softmax Classifier (三个隐含层)

    程序实现 softmax classifier, 含有三个隐含层的情况.activation function 是 ReLU : f(x)=max(0,x) f1=w1x+b1 h1=max(0,f1 ...

  10. matplotlib油漆基础

    http://blog.csdn.net/pipisorry/article/details/37742423 matplotlib介绍 matplotlib 是python最著名的画图库,它提供了一 ...