Hash

原来其他hash与字符串hash不一样啊。。。

数组根本不用开那么大,够用就行了啊。。

实践是检验真理的唯一标准。。。

Luogu

P4305不重复数字(板子)

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 
 5 using namespace std;
 6 
 7 typedef long long ll;
 8 
 9 inline ll read(){
10     ll ans = 0;char last = ' ',ch = getchar();
11     while(ch < '0'||ch > '9')last = ch,ch = getchar();
12     while('0' <= ch&&ch <= '9')ans = ans*10+ch-'0',ch = getchar(); 
13     if(last == '-')return -ans;return ans;
14 }
15 
16 const int p = 1000003;
17 
18 int Hash[p];
19 int t,x,n;
20 
21 inline void work(int x){
22     int y = x%p;
23     if(Hash[y] == x)return;
24     while(Hash[y]&&Hash[y] != x)y = (y+1)%p;
25     if(Hash[y] == x)return;
26     Hash[y] = x;
27     printf("%d ",x);
28 }
29 
30 int main(){
31     t = read();
32     while(t--){
33         n = read();
34         memset(Hash,0,sizeof(Hash));
35         while(n--){
36             x = read();
37             work(x);
38         }
39         printf("
");
40     }
41 return 0;
42 }
原文地址:https://www.cnblogs.com/Wangsheng5/p/11546362.html