poj-2406(字符串hash)
题目链接:传送门
思路:字符串hash,终止条件竟然判断错了,真是太大意了。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = ;
typedef unsigned long long ULL;
ULL power[maxn],a[maxn],b=,tmp;
char str[maxn];
int main(void)
{
int len,i,j,cnt,fg,ans;
for(power[]=,i=;i<maxn;i++) power[i]=power[i-]*b;
while(scanf("%s",str+))
{
if(strcmp(str+,".")==) break;
len=strlen(str+);
for(a[]=,i=;i<=len;i++) a[i]=a[i-]*b+(ULL)str[i];
for(i=;i<=len;i++)
{
if(len%i) continue;
tmp=a[i]-a[]*power[i];
for(j=;j+i<=len&&a[j+i]-a[j]*power[i]==tmp;j+=i) ;
if(j+i>len)
{
printf("%d\n",len/i);
break;
}
}
}
return ;
}
poj-2406(字符串hash)的更多相关文章
- POJ 1200 字符串HASH
题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有 ...
- poj 1200字符串hash
题意:给出不同字符个数和子串长度,判断有多少个不同的子串 思路:字符串hash. 用字符串函数+map为什么会超时呢?? 代码: #include <iostream> #include ...
- poj 2503 字符串hash
题目链接:http://poj.org/problem?id=2503 代码: #include<cstdio> #include<cstring> #include<i ...
- 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774
Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...
- POJ 3865 - Database 字符串hash
[题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...
- POJ 1743 Musical Theme (字符串HASH+二分)
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15900 Accepted: 5494 De ...
- poj 3461 字符串单串匹配--KMP或者字符串HASH
http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include ...
- 字符串hash - POJ 3461 Oulipo
Oulipo Problem's Link ---------------------------------------------------------------------------- M ...
- Palindrome POJ - 3974 (字符串hash+二分)
Andy the smart computer science student was attending an algorithms class when the professor asked t ...
- POJ 3461 Oulipo(字符串hash)
题目链接 字符串hash判断字符串是否相等. code #include<cstdio> #include<algorithm> #include<cstring> ...
随机推荐
- CardView 卡片布局
转自:https://www.baidu.com/link?url=WwHvfX3PB_egfQ6GFwxsDeq4NDzB2AW-zaTzskkNXs0qWnIcHyh3pN3Oqe6YO1lAmV ...
- [剑指Offer]48-最长不含重复字符的子字符串(递归思想,循环实现)
题意 如题,字符串只含a-z,输出该子串长度.例:"arabcacfr",输出4. 解题思路 递归思想 计f(i)为以第i个字符结尾的最长不含重复字符的子串长度. 状态转移:计d为 ...
- 1.尽量以const ,enum,inline替换define
1.#define为预处理阶段命令 原因:有可能记号名称没有进入记号表,而出现编译错误,即编译器并没看到过该定义. class专属常量const 一般定义为static,保证该常量至多有一份实体. 枚 ...
- 数据库(mysql)
一.left join right join inner join left join(左连接),在两张表进行连接查询时,会返回左表所有的行,即使在右表中没有匹配的记录. right join(右 ...
- 将tomcat做成windows服务
@参考文章 大致步骤: 1,配置环境变量(选读) 2,安装 3,卸载(选读) 配置环境变量: 这块不是必须的.我不喜欢给tomcat配置环境变量,默认即可.如需要配置可看参考文章,也可参考我之前的文章 ...
- Java后端工程师的学习技术栈
https://loveincode.cnblogs.com/
- ubuntu下安装nginx1.11.10
(本页仅作为个人笔记参考) 为openssl,zlib,pcre配置编译 wget http://om88fxbu9.bkt.clouddn.com/package/nginx/nginx-1.11. ...
- css兼容性写法大全
淘宝初始化代码 body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset ...
- Requested a new session but one was in progress
作为appium初学者,估计很多人都会遇到这个错误.如何解决: 1.环境变量中去掉appium的安装路径,添加Appium\node_modules\.bin这个路径进去. 2.启动cmd 输入app ...
- mysql 复制原理与实践
复制功能是将一个mysql数据库上的数据复到一个或多个mysql从数据库上. 复制的原理:在主服务器上执行的所有DDL和DML语句都会被记录到二进制日志中,这些日志由连接到它的从服务器获取,并复制到从 ...