题目链接:传送门

思路:字符串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)的更多相关文章

  1. POJ 1200 字符串HASH

    题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有 ...

  2. poj 1200字符串hash

    题意:给出不同字符个数和子串长度,判断有多少个不同的子串 思路:字符串hash. 用字符串函数+map为什么会超时呢?? 代码: #include <iostream> #include ...

  3. poj 2503 字符串hash

    题目链接:http://poj.org/problem?id=2503 代码: #include<cstdio> #include<cstring> #include<i ...

  4. 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774

    Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...

  5. POJ 3865 - Database 字符串hash

    [题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...

  6. POJ 1743 Musical Theme (字符串HASH+二分)

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15900   Accepted: 5494 De ...

  7. poj 3461 字符串单串匹配--KMP或者字符串HASH

    http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include ...

  8. 字符串hash - POJ 3461 Oulipo

    Oulipo Problem's Link ---------------------------------------------------------------------------- M ...

  9. Palindrome POJ - 3974 (字符串hash+二分)

    Andy the smart computer science student was attending an algorithms class when the professor asked t ...

  10. POJ 3461 Oulipo(字符串hash)

    题目链接 字符串hash判断字符串是否相等. code #include<cstdio> #include<algorithm> #include<cstring> ...

随机推荐

  1. Anaconda常用命令大全

    使用conda 首先我们将要确认你已经安装好了conda 配置环境 下一步我们将通过创建几个环境来展示conda的环境管理功能.使你更加轻松的了解关于环境的一切.我们将学习如何确认你在哪个环境中,以及 ...

  2. Union and Intersection of two sorted lists 并集和交集

    跟面试官确认是arrayList还是singly-linked list /*  Union 并集:两个升序的list a, b, 返回其并集(升序排序)*/ public class UnionTw ...

  3. StringBuffer 和 StringBuilder 类

    当对字符串进行修改的时候,需要使用 StringBuffer 和 StringBuilder 类. 和 String 类不同的是,StringBuffer 和 StringBuilder 类的对象能够 ...

  4. Java02-java语法基础(一)数据类型

    Java02-java语法基础(一)数据类型 一.语法基础 语句:以分号(;)结束 System.out.println(“Hello World !”); 语句块:用一组花括号({})括起来 { … ...

  5. 数据库存储 datetime,时差问题

    var offset = moment().utcOffset(); var localText = moment.utc(datetime from database).utcOffset(offs ...

  6. Object转为Bigdecimal

    import java.math.BigDecimal; import java.math.BigInteger; public class MathUtils { public static Big ...

  7. mysql 主从数据不一致 Slave_SQL_Running: No 解决方法

    在slave服务器上通过如下命令 mysql> show slave status\G; 显示如下情况: Slave_IO_Running: Yes Slave_SQL_Running: No ...

  8. php 多进程 父进程的阻塞与非阻塞

    php中进程的阻塞,主要是父进程等待子进程退出. 1.php代码如下: <?php //定义进程数量 define('FORK_NUMS', 5); //用于保存进程pid $pids = ar ...

  9. centos7下haproxy1.7的使用与配置

    centos7下haproxy1.7的使用与配置 haproxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用性.负载均衡,以及基于TCP和HTTP的应用程序代理. 一.haproxy下载 ...

  10. VSS源代码管理器运行代码分析工具的命令

    当你发现代码库总是报需要联系管理员运行代码分析工具时,你可以使用命令分析代码库代码解决: To fix the database problems, you can restart the analy ...