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> ...
随机推荐
- 颜色 color
在res/values文件夹下的color.xml添加 <?xml version="1.0" encoding="utf-8"?> <res ...
- CTF题-http://120.24.86.145:8002/flagphp/:Bugku----flag.php
今天做了一道关于序列化的题目,收益颇多,愉快地开始. 首先,提示了“hint”,所以尝试加入hint参数.这儿没啥好说的,最后hint=1显示了重点内容.如下图所示 没错,是金灿灿的网页代码,开心,仔 ...
- xshell实时跟踪日志与中文乱码设置
1.实时跟踪日志命令 tail -f logName.log 动态查看名为logName的日志信息 ctrl+c 退出实时跟踪 2.中文乱码设置 在Xshell.putty.SSH Secure Sh ...
- Django+Uwsgi+Nginx部署
一 uwsgi介绍 uWSGI是一个Web服务器,它实现了WSGI协议,uwsgi, http等协议. Nginx中HttpUwsgiMoule的作用是与uWSGI服务器进行交换 1 WSGI是一种W ...
- 为ListView的子列表添加不同的响应事件
如何实现当点击不同的listView中的每个子列表出发不同的事件? 当在布局中,设置对应的ListView主布局及对应子布局时,在Activity中向ListView中添加子列表,利用每个子列表的Po ...
- Python ctypes.windll.user32() Examples
Example 1 Project: OSPTF Author: xSploited File: mouselogger.py View Source Project 7 votes def ...
- u-boot之start_armboot函数分析
在分析start.S文件过程中提到过,最后从汇编跳到C函数执行的是start_armboot函数,位于lib_arm\board.c文件下,它的执行流程图如下,截图来源于<嵌入式LINUX应用开 ...
- spring/spirng boot添加fluent日志-aop
此项目以aop的形式添加fluent 日志 sample介绍 spring-mvc-aop-helloworld 为spring mvc aop condition toolcommontest 为s ...
- svn conflict问题解决办法
转自:http://www.cnblogs.com/aaronLinux/p/5521844.html 目录: 1. 同一处修改文件冲突 1.1. 解决方式一 1.2. 解决方式二 1.3. 解决总结 ...
- C++/CLI学习入门
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxIAAAFlCAYAAAB/fN6bAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw