http://acm.dlut.edu.cn/problem.php?id=1251
先把两个串的hash值都求出来,然后用二分答案的方法枚举子串的长度,把一个串的所有该长度的子串的hash值放进hashtable里面,用另一个串的该长度的子串的hash值去hashtable里查找有没有。如果找到了答案就去找更长长度的子串,否则找更短长度的。
二分确实很好用,如果有单调性的话尽量考虑使用,可以把n的复杂度简化为logn。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef unsigned long long ll;
const int maxn=100005;
const int mod=100007;
const int base=131;
char a[maxn],b[maxn];
ll H[maxn],xp[maxn],h[maxn];
struct xx{
int next;
ll n;
}vis[4*mod];
int head[mod],top,ans;
struct hashtable{
int hash(ll x){
return x%mod;
}
void clear(){
memset(head,-1,sizeof(head));
top=0;
}