题目链接:点击打开链接

#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的更多相关文章

  1. CodeForces - 7D Palindrome Degree

    最近接触了一点字符串算法,其实也就是一个简单的最大回文串算法,给定字符串s,求出最大字符串长度. 算法是这样的, 用'#'将s字符串中的每个字符分隔,比如s = "aba",分割后 ...

  2. Codeforces Beta Round #7 D. Palindrome Degree —— 字符串哈希

    题目链接:http://codeforces.com/contest/7/problem/D D. Palindrome Degree time limit per test 1 second mem ...

  3. CodeForces 1056E - Check Transcription - [字符串hash]

    题目链接:https://codeforces.com/problemset/problem/1056/E One of Arkady's friends works at a huge radio ...

  4. Palindrome Degree(hash的思想题)

    个人心得:这题就是要确定是否为回文串,朴素算法会超时,所以想到用哈希,哈希从左到右和从右到左的key值一样就一定是回文串, 那么问题来了,正向还能保证一遍遍历,逆向呢,卡住我了,后面发现网上大神的秦九 ...

  5. Codeforces Beta Round #7--D. Palindrome Degree(Manacer)

    题目:http://blog.csdn.net/winddreams/article/details/44218961 求出每一个点为中心的最长字符串,推断该串是不是从开头的回文串. #include ...

  6. Codeforces Beta Round #7 D. Palindrome Degree hash

    D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...

  7. Palindrome POJ - 3974 (字符串hash+二分)

    Andy the smart computer science student was attending an algorithms class when the professor asked t ...

  8. Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp

    题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...

  9. 【codeforces 514C】Watto and Mechanism(字符串hash)

    [题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在 ...

随机推荐

  1. php实现简单验证码的功能

    php实现简单验证码的功能 <!DOCTYPE html> <html> <head lang="en"> <meta charset=& ...

  2. [xPlugin] smartupload jsp图片上传

    URL:http://www.cnblogs.com/ISeeYouBlogs/p/jsp.html 1.要实现图片上传,首先需要一个组件,这里我用的是smartupload.jar可以到这里下载ht ...

  3. Angular2之路由学习笔记

    目前工作中项目的主要技术栈是Angular2 在这里简单记录一下遇到的问题以及解决方案. 这篇笔记主要记录Angular2 的路由. 官方文档链接:https://angular.cn/docs/ts ...

  4. C - Pocket Book(set)

    Problem description One day little Vasya found mom's pocket book. The book had n names of her friend ...

  5. powershell遍历文件夹设置权限,解决文件无法删除的问题。

    function set-rights ($path) { $p = Get-Item $path; if ($p.Attributes -eq 'Directory') { foreach ($ch ...

  6. 编译OpenCV遇到Qmake问题

    1.Ubuntu安装OpenCv,出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or ...

  7. Js中的4个事件

    除了加载文档的事件onload和鼠标相关的一些事件如onclick,onmouseover等.js还有一些相对不常用的事件,这些事件也有各自的应用场景,本文就介绍 onkeydown,oncontex ...

  8. Bootstrap 有一个 class 属性叫做 well,它的作用是为设定的列创造出一种视觉上的深度感

    Bootstrap 有一个 class 属性叫做 well,它的作用是为设定的列创造出一种视觉上的深度感

  9. python tips:生成器的小问题

    在Python中,生成器和函数很像,都是在运行的过程中才会去确定各种变量的值,所以在很多情况下,会导致各种各样的问题. def generator_test1(): # 0...9 generator ...

  10. gitlab安装和汉化

    Centos 7.x 安装 gitlab-ce-8.8.0-ce 一.安装配置依赖项 yum -y install curl unzip policycoreutils git wget # 依赖包 ...