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> ...
随机推荐
- httpclient和htpUrlConnection用例
使用了很久框架,突然不知道,原生访问网络请求方式,回过头去看,还好,对现在流行使用okhttp也有了更深体会. HttpURLConnection介绍: HttpURLConnection是一种多用途 ...
- unity 3d音效如何设置?,近大远小
请问怎么将导入的音频文件设置为“3D Sound”?这是我导入的音频文件: 现在3D音效的设置不在导入音效文件的地方,而是在AudioSource的SpatialBlend属性,0表示2D,1表示3D ...
- JavaScript各种继承方式(四):原型式继承(prototypal inheritance)
一 原理 利用工具函数,通过原型对象直接得到父类的实例,并当作子类对实例使用. function inherit(obj){ // 在闭包中创建子类,对外隐藏子类 function Temp(){ } ...
- PHP-自动加载原理分析
说起PHP的自动加载,很多同学可能都会想到各种框架的自动加载功能,PHP规范中的PSR0和PSR4原则,Composer的自动加载功能等等,这些都为我们的开发提供了很大的方便. 那么PHP自动加载的前 ...
- HDU 2680 Choose the best route(SPFA)
Problem DescriptionOne day , Kiki wants to visit one of her friends. As she is liable to carsickness ...
- mysql学习1:数据类型:数字型,日期和时间,字符串类型(总结)
mysql数据类型:数字型,日期和时间,字符串类型 摘要 MySQL中定义数据字段的类型对数据库的优化是非常重要的: MySQL支持多种类型,大致可以分为三类,如下. 数字类型 整数:tinyint. ...
- Django具体操作(五)
一.中间件的概念 中间件顾名思义,是介于request与response处理之间的一道处理过程,相对比较轻量级,并且在全局上改变django的输入与输出.因为改变的是全局,所以需要谨慎实用,用不好会影 ...
- Intellij Idea创建Android项目
创建工程前请已下载安装好了Intellij Idea和Android SDK. Intellij idea 2016.3.2 步骤 Android SDK设置 在FIle –> Other Se ...
- IIS下载,WebClient().DownloadFile下载
new System.Net.WebClient().DownloadFile(serverPath, localPath); 有时候使用的时候,文件下载不下来.需要设置一下服务器上IIS的权限
- MySQL安装(windows版本)
1.下载.MySQL http://dev.mysql.com/downloads/mysql/ 下载windows的zip包,解压后,添加path路径bin, 系统环境变量->path-> ...