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 题意 构造一个只含有灰.白块的网格,要求: 所有灰块为一个连通块 每个灰块与偶数个灰块相邻 恰有 ...
随机推荐
- 可视化格式模型(visual formatting model)
原文 简书原文:https://www.jianshu.com/p/7632f16ff555 大纲 1.认识可视化模型 2.可视化模型的内容 3.可视化模型的影响因素 1.认识可视化模型 盒子模型是C ...
- 自己写的关于生产者与消费者模式,还有定时任务的demo
为了加深对生产者消费者模式的理解,特意写了这个demo,里面还包含了一个自己写的定时任务.代码下载地址:http://download.csdn.net/detail/li_yan_fei/98115 ...
- word中公式的排版及标题列表
1.首先建好你的标题,如标题1,标题2等等,你能够依次改变它们的字体,段落等格式,新建格式例如以下图所看到的 红圈处即建立新的格式,你能够建立不论什么你想要的格式,非常方便: 2.当你建立好了多个标题 ...
- Socket编程模型之完毕port模型
转载请注明来源:viewmode=contents">http://blog.csdn.net/caoshiying?viewmode=contents 一.回想重叠IO模型 用完毕例 ...
- ios_webView
iOS开发中WebView的使用 在AppDelegate.m文件里 view sourceprint" class="item about" style="c ...
- Android屏幕信息获取
Android中有时需要获取屏幕的size信息以便对控件位置进行动态控制,最近做了一些研究,现在将获取屏幕大小信息的方法总结如下,可能存在一些地方理解的不全面. 1.getMetrics Displa ...
- tky项目第②个半月总结
在上一篇半月总结中,介绍了tky项目的整体架构.项目的进展情况.项目的优势与开发中存在的问题等.今天来聊聊这半个月中,项目中发生的事情. 在这半个月中,项目中有了较大的突破:成功通过了国家评測中心的測 ...
- Android 多个Fragment嵌套导致的三大BUG
Android有碎片化的问题,当然本文说的碎片化不是指的系统版本碎片化的问题,而是Fragment组件碎片化的问题. 很久之前,在Android 3.1系统发布的时候,Google推出了使用Fragm ...
- iOS 通讯录基础
iOS 6 之后应用訪问通讯录须要获得用户授权,而且仅仅授权一次,即使卸载了之后再安装.也不用再次授权. 开发通讯录应用须要两个框架: 1.ABAddressBook 主要用于提供訪问通讯录中 ...
- Graphics-Processing Architecture Based on Approximate Rendering
BACKGROUND The present invention generally relates to the processing of graphics data, and particula ...