CodeForces 7D Palindrome Degree 字符串hash
题目链接:点击打开链接
#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的更多相关文章
- CodeForces - 7D Palindrome Degree
最近接触了一点字符串算法,其实也就是一个简单的最大回文串算法,给定字符串s,求出最大字符串长度. 算法是这样的, 用'#'将s字符串中的每个字符分隔,比如s = "aba",分割后 ...
- 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 1056E - Check Transcription - [字符串hash]
题目链接:https://codeforces.com/problemset/problem/1056/E One of Arkady's friends works at a huge radio ...
- Palindrome Degree(hash的思想题)
个人心得:这题就是要确定是否为回文串,朴素算法会超时,所以想到用哈希,哈希从左到右和从右到左的key值一样就一定是回文串, 那么问题来了,正向还能保证一遍遍历,逆向呢,卡住我了,后面发现网上大神的秦九 ...
- Codeforces Beta Round #7--D. Palindrome Degree(Manacer)
题目:http://blog.csdn.net/winddreams/article/details/44218961 求出每一个点为中心的最长字符串,推断该串是不是从开头的回文串. #include ...
- Codeforces Beta Round #7 D. Palindrome Degree hash
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...
- Palindrome POJ - 3974 (字符串hash+二分)
Andy the smart computer science student was attending an algorithms class when the professor asked t ...
- 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 514C】Watto and Mechanism(字符串hash)
[题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在 ...
随机推荐
- hdoj--1150--Machine Schedule(最小点覆盖)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Eclipse-Error:笔记-1
ylbtech-Eclipse-Error:笔记-1 1.返回顶部 1. Whitelabel Error PageThis application has no explicit mapping f ...
- 免费获取Bootstrap模板的方法
Bootstrap是Twitter推出的一个开源的用于前端开发的工具包,其中中包含了丰富的Web组件,根据这些组件,可以快速的搭建一个漂亮.功能完备的网站. 最近通过了Bootstrap中文网学习了其 ...
- Tomcat 日志切割
一.installing 日志轮训工具 yum install cronolog -y 二.安装.修改tomcat文件 wget http://mirrors.shuosc.org/apache/ ...
- bind()函数的作用
bind()函数是Function原型上的一个属性,当某个函数调用此方法时,可以通过向bind()函数传入执行对象和调用bind的函数的参数来改变函数的执行对象 /*问题:改变func执行环境,使之输 ...
- P1629 邮递员送信(未完成)
题目描述 有一个邮递员要送东西,邮局在节点1.他总共要送N-1样东西,其目的地分别是2~N.由于这个城市的交通比较繁忙,因此所有的道路都是单行的,共有M条道路,通过每条道路需要一定的时间.这个邮递员每 ...
- hdu2282 Chocolate 完美匹配 + 拆点
题意: N个箱子排成一个圈,所有的箱子里的巧克力的数量加起来不大于N,每次可以把箱子里的巧克力向旁边的箱子转移(两个方向),问要让每个箱子里的巧克力不大于1的最小步数. 分析: 把巧克力大于1的箱子拆 ...
- fopen函数打开文件总是返回NULL错误
有时候,调用fopen函数用来打开文件,但是总会返回NULL.对于此类问题.一定是一下两种原因之一造成的. 1.路径错误.(路径中斜杠和反斜杠的问题) 2.文件在另一个进程中被打开,再次打开当然不行( ...
- PCL:解决PCL和OpenCV冲突的方法
不是PCL的问题,而是OpenCV的问题. (1):先包含PCL库,再包含OpenCV库: (2):把里面的UCHAR冲突全部换掉! 如果你有闲情逸致,用正则表达式 慢慢替换去吧! (3):或者把F ...
- C#——面对对象之封装、继承、多态的简单理解
一.封装 隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读取和修改的访问级别. 简单来多,就是讲我们所需要的代码打包封装进入一个类里面,便于我们调用,操作.这就是封装. 这样就隔离了具体 ...