codeforces 7D Palindrome Degree 字符串hash
来源:互联网 发布:幻城网络剧原声带 编辑:程序博客网 时间:2024/05/21 22:43
如果一个长度为n的字符串s,如果前[n/2]和后[n/2]位相同,并且是k-1度回文串,那么s为k度回文串,求一个字符串所有前缀的度数的和。
f[i]记录一下前i位的度数,没扫描以为更新一下前缀的正hash值和反hash值,如果这两个值相同,那么更新f[i]=f[i>>1]+1;并且累加度数,最后输出结果就行。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>#include <queue>using namespace std;typedef unsigned long long ull;typedef long long ll;int n,m;char s[10100000];int f[10100000];const ull x=257;int main(){// freopen("in.txt","r",stdin); while(~scanf("%s",s)) { ull l=0,r=0,e=1; int len=strlen(s); memset(f,0,sizeof f); ull ans=0; for (int i=0; i<len; i++) { l=l*x+s[i]; r=s[i]*e+r; e*=x; if (l==r) ans+=(f[i+1]=f[(i+1)>>1]+1); } cout<<ans<<endl; } return 0;}
0 0
- codeforces 7D Palindrome Degree 字符串hash
- CodeForces 7D Palindrome Degree 字符串hash
- Codeforces 7D Palindrome Degree 字符串hash DP
- Codeforces Beta Round #7--D. Palindrome Degree(hash)
- Codeforces Beta Round #7 D. Palindrome Degree —— hash
- CodeForces - 7D Palindrome Degree
- CodeForces 7D Palindrome Degree
- codeforces 7D Palindrome Degree
- [数据结构-hash]CF 7D Palindrome Degree
- Codeforces Beta Round #7 D. Palindrome Degree
- Codeforces Beta Round #7, problem: (D) Palindrome Degree
- Codeforces Beta Round #7--D. Palindrome Degree(Manacer)
- CF 7D: Palindrome Degree
- Codeforce 7D Palindrome Degree
- #7 D. Palindrome Degree (manacher + dp)
- [codeforces] 501E - Misha and Palindrome Degree
- Codeforces round 244(div.2) D match&catch【字符串hash】
- 【字符串hash】 codeforces 471D MUH and Cube Walls
- phpize报cannot find autoconf
- 服务器流量异常的解决方案
- android__9.png图片
- 大批量数据更新,分享给大家。
- 谈谈Runtime类中的freeMemory,totalMemory,maxMemory等几个方法
- codeforces 7D Palindrome Degree 字符串hash
- 《大话设计模式》—— 读后感 (12)牛市股票还会亏钱?—— 外观模式
- Queue的一般用法
- java服务器搭建(二)数据库连接
- 程序员面试智力题 (5)
- (java)利用BASE64编码和解码图片文件
- crm2011的字段类型
- MPC 编译
- OSPF数据包类型