原来其他 hash 与字符串 hash 不一样啊...
数组根本不用开那么大, 够用就行了啊..
实践是检验真理的唯一标准...
Luogu
P4305 不重复数字 (板子)
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- using namespace std;
- typedef long long ll;
- inline ll read(){
- ll ans = 0;char last = ' ',ch = getchar();
- while(ch <'0'||ch> '9')last = ch,ch = getchar();
- while('0' <= ch&&ch <= '9')ans = ans*10+ch-'0',ch = getchar();
- if(last == '-')return -ans;return ans;
- }
- const int p = 1000003;
- int Hash[p];
- int t,x,n;
- inline void work(int x){
- int y = x%p;
- if(Hash[y] == x)return;
- while(Hash[y]&&Hash[y] != x)y = (y+1)%p;
- if(Hash[y] == x)return;
- Hash[y] = x;
- printf("%d",x);
- }
- int main(){
- t = read();
- while(t--){
- n = read();
- memset(Hash,0,sizeof(Hash));
- while(n--){
- x = read();
- work(x);
- }
- printf("\n");
- }
- return 0;
- }
- Hash
来源: http://www.bubuko.com/infodetail-3203954.html