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 题意 构造一个只含有灰.白块的网格,要求: 所有灰块为一个连通块 每个灰块与偶数个灰块相邻 恰有 ...
随机推荐
- SDI与ASI 接口具体解释介绍
分量编码 在对彩色电视信号进行数字化处理和传输是.一种经常使用的方式是分别对其3个分量(Y,R-Y.B-Y)进行数字化编码.这就是分量分量编码.另外还有全信号编码,全信号编码是对彩色全电视信号直接进行 ...
- AndroidAnnotations使用说明书—AndroidAnnotations是怎样工作的?
AndroidAnnotations的工作方式非常easy.它使用标准的java注入处理工具,自己主动加入了一个额外的编译步骤来生成源码. 源代码是什么?每个增强的类,比方每个用@EActivity注 ...
- 从源码角度实现一个自己的Promise
原文链接:https://geniuspeng.github.io/2017/12/14/my-promise/ 关于Promise的概念以及意义就不在这里介绍了,最近看到了一些实现Promise的核 ...
- Spring的事务管理和数据库事务相关知识
1 初步理解 理解事务之前,先讲一个你日常生活中最常干的事:取钱. 比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱. ...
- [内核编程] 4.5 HOOK分发函数
4.5 HOOK分发函数 本节开始深入的探讨键盘的过滤与反过滤.有趣的是,无论是过滤还是反过 滤,其原理都是进行过滤.取胜的关键在于:谁将第一个得到信息. 黑客可能会通过修改一个已经存在的驱动对象(比 ...
- Django之分页显示文章
1.项目:http://www.cnblogs.com/jasonhaven/p/7493422.html 2.任务描述:页面分页显示文章 3.源代码 后台: from django.core.pag ...
- 【b602】金明的预算方案
Time Limit: 1 second Memory Limit: 50 MB [问题描述] 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈 ...
- hadoop集群ambari搭建(1)之ambari-server安装
Apache Ambari是一种基于Web的工具,支持Apache Hadoop集群的供应.管理和监控. Ambari眼下已支持大多数Hadoop组件,包含HDFS.MapReduce.Hive.Pi ...
- 机器学习: Softmax Classifier (三个隐含层)
程序实现 softmax classifier, 含有三个隐含层的情况.activation function 是 ReLU : f(x)=max(0,x) f1=w1x+b1 h1=max(0,f1 ...
- matplotlib油漆基础
http://blog.csdn.net/pipisorry/article/details/37742423 matplotlib介绍 matplotlib 是python最著名的画图库,它提供了一 ...