Hash
穷源溯流
路很长,尽管走便是。
展开
-
洛谷 SP7586 NUMOFPAL - Number of Palindromes(字符串hash)
暴力枚举 [l,x1] [x2,r] 判断这两段字符串是否相等即可,其中 x1-l+1=r-x2+1时间复杂度 O(n^2)虽然可以水过这个题,但是时间复杂度并不是我们想要的const int N=1e5+5;const int base=2333; int n,m; int i,j,k; char s[N]; ull xp[N]; ull h[N],_h[N];void init(){ xp[0]=1; for(in...原创 2021-03-27 18:45:59 · 145 阅读 · 0 评论 -
Loj #2823. 「BalticOI 2014 Day 1」三个朋友(字符串hash)
题目需要会求修改后的哈希值题目中需要注意的 ’UNIQUE‘ 的时候是存在不相同的字符串,而不是不相同的位置const int N=2e6+5;const int base=2333; int n,m; int i,j,k; char s[N]; ull xp[N]; ull h[N];void init(){ xp[0]=1; for(int i=1;i<N;i++) xp[i]=xp[i-1]*base;...原创 2021-03-27 15:55:29 · 265 阅读 · 0 评论 -
POJ 2752 && 1458:Seek the Name, Seek the Fame
const int N=1e6+5; int n,m,t; int i,j,k; //int a[N]; char s[N]; ull power[N]; ull h[N]; const int b=131;bool C(int x,ull val){ int p=n-x; if( h[n]-h[p]*power[x]==val ) return true; return false;}int main(...原创 2020-09-14 17:02:25 · 239 阅读 · 0 评论 -
1459:friends
#pragma GCC optimize(2)#include <bits/stdc++.h>#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <utility>...原创 2020-09-16 08:46:51 · 625 阅读 · 0 评论 -
POJ 2406 && 1457:Power Strings
const int N=1e6+5; int n,m,t; int i,j,k; //int a[N]; char s[N]; ull power[N]; ull h[N]; const int b=131;bool C(int len,ull val,int x){ for(int i=0;i<len;i+=x){ if(h[i+x]-h[i]*power[x]!=val) return false;...原创 2020-09-14 16:50:04 · 168 阅读 · 0 评论 -
1455:Oulipo(字符串 Hash)
const int N=1e6+5; int n,m,t; int i,j,k; //int a[N]; char s[N],s1[N]; ull power[N]; ull h[N];int main(){ IOS; power[0]=1; const int b=131; for(i=1;i<=1e6;i++){ power[i]=power[i-1]*b; } rus...原创 2020-09-14 15:52:49 · 300 阅读 · 0 评论