码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 7D Palindrome Degree 字符串hash

时间:2014-06-27 07:35:50      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:class   code   http   tar   com   get   

题目链接:点击打开链接





#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 5001000
#define mod 1000000007
#define hehe 137731735
#define ll __int64
ll n;
char s[N];
ll x[N], y[N];
ll dp[N];
int main(){
	ll i,j;
	while(gets(s)) {
		dp[0] = 0;
		for(i=0;s[i];i++) {
			if('0'<=s[i]&&s[i]<='9')
				s[i] = s[i]-'0';
			else if('a'<=s[i]&&s[i]<='z')
				s[i] = s[i]-'a'+10;
			else s[i] = s[i]-'A'+36;
		}
		ll len = i;
		x[0] = 0;
		ll dou = 1;
		for(i=1;i<=len;i++){ x[i] = (x[i-1]+s[i-1]*dou)%mod; dou = (dou*hehe)%mod; }
		y[len+1] = 0;
		for(i=1;i<=len;i++) { y[i] = (y[i-1]*hehe+s[i-1])%mod;}
		ll ans = 0;
		for(i=1;i<=len;i++) if(x[i]==y[i]) {
			dp[i] = dp[i>>1]+1;
			ans += dp[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}


CodeForces 7D Palindrome Degree 字符串hash,布布扣,bubuko.com

CodeForces 7D Palindrome Degree 字符串hash

标签:class   code   http   tar   com   get   

原文地址:http://blog.csdn.net/qq574857122/article/details/34993183

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!