蒟蒻求助,30pts

P4305 [JLOI2011] 不重复数字

```cpp #include<map> #include<cmath> #include<stack> #include<queue> #include<vector> #include<cstdio> #include<string> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define int ll #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f #define mod 133331 #define bug(x) cout<<"Bug "<<(x)<<endl #define el cout<<endl using namespace std; inline int read() { int s=0,w=1; char ch=getchar(); while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0' && ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); return; } const int N=5e4+10; int T; int n; int a[N]; int h[mod],tot=0; int cnt=0; struct edge { int w,nxt; }e[N]; int Hash(int x) { return (x%mod+mod)%mod; } void insert(int x) { int u=Hash(x); for(int i=h[u];i;i=e[i].nxt) { if(e[i].w==x) { return; } } e[++tot].w=x; e[tot].nxt=h[u]; h[u]=tot; } int find(int x) { int u=Hash(x); for(int i=h[u];i;i=e[i].nxt) { if(e[i].w==x) { return 1; } } return 0; } void init() { memset(h,0,sizeof(h)); memset(e,0,sizeof(e)); cnt=0; } signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); T=read(); while(T--) { init(); n=read(); for(int i=1;i<=n;i++) { int x=read(); if(find(x)) continue; insert(x); a[++cnt]=x; } for(int i=1;i<=cnt;i++) { cout<<a[i]<<" "; } el; } return 0; } ```
by makerlife @ 2022-08-26 21:03:21


把tot置为0
by Deuteron @ 2022-08-26 21:43:13


```cpp #include<map> #include<cmath> #include<stack> #include<queue> #include<vector> #include<cstdio> #include<string> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define int ll #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f #define mod 133331 #define bug(x) cout<<"Bug "<<(x)<<endl #define el cout<<endl using namespace std; inline int read() { int s=0,w=1; char ch=getchar(); while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0' && ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); return; } const int N=1e5+10; int T; int n; int a[N]; int h[mod],tot=0; int cnt=0; struct edge { int w,nxt; }e[N]; int Hash(int x) { return (x%mod+mod)%mod; } void insert(int x) { int u=Hash(x); for(int i=h[u];i;i=e[i].nxt) { if(e[i].w==x) { return; } } e[++tot].w=x; e[tot].nxt=h[u]; h[u]=tot; } int find(int x) { int u=Hash(x); for(int i=h[u];i;i=e[i].nxt) { if(e[i].w==x) { return 1; } } return 0; } void init() { memset(h,0,sizeof(h)); memset(e,0,sizeof(e)); cnt=0; } signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); T=read(); while(T--) { init(); n=read(); for(int i=1;i<=n;i++) { int x=read(); if(find(x)) continue; insert(x); a[++cnt]=x; } for(int i=1;i<=cnt;i++) { cout<<a[i]<<" "; } tot=0; el; } return 0; } ```
by Deuteron @ 2022-08-26 21:43:31


@[makerlife](/user/335621) $map$ 不行吗?(雾)
by HotDogSeller @ 2022-08-26 21:57:26


@[小可爱萌萌哒](/user/397982) 啊我太智了
by makerlife @ 2022-08-27 10:58:55


@[BTOI](/user/540822) 我主要是想练 hash
by makerlife @ 2022-08-27 10:59:26


@[小可爱萌萌哒](/user/397982) 一个求助帖竟然炸出了韩老师/kel
by makerlife @ 2022-08-27 11:03:11


已过,此帖终
by makerlife @ 2022-08-27 11:03:34


|