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> ...
随机推荐
- Cisco ASR1002-X告警处理
客户反馈其机房的ASR100X告警,拍照如下图: 处理步骤: 查看日志未发现异常 查看CPU/内存/风扇未发现异常 3.清除告警#clear facility alarm依旧告警 4.shutdown ...
- Angular之RouterModule的forRoot与forChild
Angular 提供了一种方式来把服务提供商从模块中分离出来,以便模块既可以带着 providers 被根模块导入,也可以不带 providers 被子模块导入. 区别: `forRoot` crea ...
- Linux 有线 校园网
1.首先在ifconfig命令在终端查看自己的ip地址,然后记录下来 2.然后用sudo -i 命令转换到root权限下 3.在自己家目录下输入pppoeconf 4.遇到username时,讲自己的 ...
- 100-days: Five
Title: Feel better now ? The rise and rise of the anxiety economy(焦虑经济) rise and rise 一直上升 anxiety n ...
- f5负载均衡算法
负载均衡使用一种算法或公式来确定由哪一个后台服务器接收流量 负载均衡是基于连接的 1.静态负载均衡算法:以固定方式分发连接 轮询算法(Round Robin):将请求依次顺序循环地分发给服务器,从1到 ...
- linux命令学习之:vim
1. 关于Vim vim是我最喜欢的编辑器,也是linux下第二强大的编辑器. 虽然emacs是公认的世界第一,我认为使用emacs并没有使用vi进行编辑来得高效. 如果是初学vi,运行一下vimtu ...
- 使用go语言的list实现一个简单的LRU缓存
package main; import ( "container/list" "errors" "sync" "fmt" ...
- 自己在完第一遍STL和Directx 9.0 游戏开发编程基础书后的体会
如果一本书看一遍就能看懂,说明书对自己相对容易,没有必要在去看第二遍,但是对于大多数书籍,都有自己陌生的知识,看完一遍无法理解的地方,说明就是自己知识点最薄弱的,最需要去理解的地方,一旦自己理解了这些 ...
- C# 判断ip地址是否正确
最后要用一方法判断ip地址是否正确,直接用.Net现成的类,方法如下: string ipStr="192.168.222.333"; IPAddress ip; if(IPAdd ...
- hdu 4717(三分) The Moving Points
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 n个点,给出初始坐标和移动的速度和移动的方向,求在哪一时刻任意两点之间的距离的最大值的最小. 对于最 ...