【CF】7 Beta Round D. Palindrome Degree
manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件。
/* 7D */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 5e6+;
int dp[maxn];
int Len[maxn*];
char s[maxn];
char d[maxn*]; void init() {
int slen = strlen(s);
int j = ; d[j++] = '$';
d[j++] = '#';
rep(i, , slen) {
d[j++] = s[i];
d[j++] = '#';
}
} void manacher() {
int dlen = strlen(d);
int p = , p0 = ; rep(i, , dlen) {
if (p > i)
Len[i] = min(p-i, Len[*p0-i]);
else
Len[i] = ;
while (d[i+Len[i]] == d[i-Len[i]])
++Len[i];
if (i + Len[i] > p) {
p = i + Len[i];
p0 = i;
}
}
} void solve() {
init();
manacher(); int slen = strlen(s);
int ans = ; dp[] = ;
rep(i, , slen+) {
if (Len[i+] >= i+) {
dp[i] = dp[i>>] + ;
}
ans += dp[i];
} printf("%d\n", ans);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%s", s);
solve(); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【CF】7 Beta Round D. Palindrome Degree的更多相关文章
- 【计算几何】 Codeforces Beta Round #67 (Div. 2) E. Ship's Shortest Path
读懂题意其实是模板题.就是细节略多. #include<cstdio> #include<cmath> #include<algorithm> using name ...
- Codeforces Beta Round #7--D. Palindrome Degree(Manacer)
题目:http://blog.csdn.net/winddreams/article/details/44218961 求出每一个点为中心的最长字符串,推断该串是不是从开头的回文串. #include ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- 【概率论】5-8:Beta分布(The Beta Distributions)
title: [概率论]5-8:Beta分布(The Beta Distributions) categories: - Mathematic - Probability keywords: - Th ...
- 【题解】Comet OJ Round 70 简要题解
[题解]Comet OJ Round 70 简要题解 A 将放在地上的书按照从小到大排序后,问题的本质就变成了合并两个序列使得字典序最小.可以直接模拟归并排序.直接用循环和std::merge实现这个 ...
- 【扫描线】Educational Codeforces Round 4 D. The Union of k-Segments
http://codeforces.com/contest/612/problem/D [题解] http://blog.csdn.net/strokess/article/details/52248 ...
- 【LOJ511】[LibreOJ NOI Round #1]验题(动态DP)
我这道题写了整!整!三!天! 我要一定要写这篇博客来表达我复!杂!的!心!情! 题目 LOJ511 官方题解(这个题解似乎不是很详细,我膜 std 才看懂的) 调这道题验证了我校某人的一句话:调题是一 ...
- 【测试】trunc和round的区别
trunc是截断:round是四舍五入:下面通过一个例子具体看一下trunc和round的不同 SQL),trunc() from dual; TRUNC() TRUNC() ------------ ...
- 【Codeforces752D】Santa Claus and a Palindrome [STL]
Santa Claus and a Palindrome Time Limit: 20 Sec Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个a ...
随机推荐
- poj2299 二分思想
poj2299 http://poj.org/problem?id=2299题意: 一个含有n个数的数组, 每次只能交换相邻的两个数, 求最少操作多少次可以使该数组变成一个有序数组(从小到大). ...
- primefaces 带参数的组件
分析了一下primefaces extension showcase的源码,总结一下组件传参的方式. 下面定义了一个组件,名为fourTabsDecoratorCustom.xhtml 1: < ...
- IOS_OC_地图与定位
知识点介绍 一. 定位 实现一次定位 CLLocation对象介绍 实现持续定位 请求用户授权 二. 地理编码 正地理编码 反地理编码 三. 地图的基本使用 显示用户位置 设置地图显示类型 根据用户位 ...
- 计数排序之python 实现源码
old = [2, 5, 3, 0, 2, 3, 0, 3] new = [0, 0, 0, 0, 0, 0] for i in range(len(old)): new[old[i]] = new[ ...
- 数据库创建&数据表创建
--第2_1题创建数据库 create database Student201038897041 on primary (name='student1', filename='F:\coures\SQ ...
- [转]maven插件的开发
原文链接: http://clojure.iteye.com/blog/1124188 另一篇文章 http://blog.csdn.net/csfreebird/article/details/77 ...
- wamp介绍
Wamp介绍 Windows下的Apache+Mysql/MariaDB+Perl/PHP/Python,一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在 ...
- php简简单单搞定中英文混排字符串截取,只需2行代码!
提到中英文混排计数.截取,大家首先想到的是ascii.16进制.正则匹配.循环计数. 今天我给大家分享的是php的mb扩展,教你如何轻松处理字符串. 先给大家介绍用到的函数: mb_strwidth( ...
- delphi发送html带附件邮件
var html: TIdText; begin if not SMTP.Connected then SMTP.Disconnect(); try SMTP.Connect; try if SMTP ...
- DelphiXE4- System.IOUtils.TDirectory笔记查询后缀名为dll的文件
TStringDynArray 在System.Types中定义