今天学字符,哈希和KMP、
KMP之前貌似听过,全部忘掉
今天好好理解了下
算法实现很简单,网上很多,自己看吧
哈希有题TLE了两次
那个P值一直没取好,后来去CSDN里看好像要取一个非常EX的数
下面有链接
https://www.ybtoj.com.cn/contest/530/problem/7
后来取这个P值就AC了
不管是取大(比如1e9+7和1e9+9)(会CE)还是取小(比如131和13331)(会TLE)都不行
#include
#define M 4194303
using namespace std;
const int L = 2e8 + 10, K = 1e4 + 10;
int a[K], h[M + 1];
int n, cnt;
int v[L], u[L];
void Hash(int x) {
int j = x & M;
cnt++;
v[cnt] = x;
u[cnt] = h[j];
h[j] = cnt;
return;
}
bool R(int x) {
int j = x & M;
for (int i = h[j]; i; i = u[i])
if (v[i] == x)
return true;
return false;
}
int Work() {
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (R(a[i] - a[j])) {
ans++;
break;
}
}
for (int j = 1; j > n;
for (int i = 1; i > a[i];
cout << Work();
return 0;
}
没了。。。