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个字符串 对于每一个询问字符串 你需要在 ...
随机推荐
- nyoj--170--网络的可靠性(水题)
网络的可靠性 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 A公司是全球依靠的互联网解决方案提供商,也是2010年世博会的高级赞助商.它将提供先进的网络协作技术,展示其 ...
- Dark roads--hdoj
Dark roads Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- Maven打包编译错误工作区间设置编码格式gbk可以utf-8不可以
转自:https://blog.csdn.net/wolf_love666/article/details/52593483 问题:Maven打包编译错误工作区间设置编码格式gbk可以utf-8不可以 ...
- Angular2之路由学习笔记
目前工作中项目的主要技术栈是Angular2 在这里简单记录一下遇到的问题以及解决方案. 这篇笔记主要记录Angular2 的路由. 官方文档链接:https://angular.cn/docs/ts ...
- rehat7.X下postgresql 11编译安装
文档目录结构: 一.准备 操作系统版本:rehat7.6 Postgresql:11.2 软件安装目录:/pgsql11/basedir 数据文件存放目录:/pgsql11data/ 11.2的下载地 ...
- Nginx实现负载均衡 + Keepalived实现Nginx的高可用
前言 使用集群是大中型网站解决高并发.海量数据问题的常用手段.当一台服务器的处理能力.存储空间不足时,不要企图去换更强大的服务器,对大型网站而言,不管多么强大的服务器,都满足不了网站持续增长的业务需求 ...
- 从 Zero 到 Hero ,一文掌握 Python--转
https://www.oschina.net/translate/learning-python-from-zero-to-hero 第一个问题,什么是 Python ?根据 Python 之父 G ...
- [Offer收割]编程练习赛42
对局匹配 直接贪心 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #i ...
- hdu2883 最大流,判断满流 优化的SAP算法
这是09年的多校联赛题目,比10年的难度要大.如果没做过hdu3572,建议先去做.有了解题思维再来做这题. 这题与hdu3572类似.但是1 <= si < ei <= 1,000 ...
- 【Oracle】ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
今天数据库在查询数据的时候显示了这个错误: ORA-01157: cannot identify/lock data file 201 - see DBWR trace file ORA-01110: ...