[bzoj]2761: [JLOI2011]不重复数字

原题链接:不重复数字

去重???输出第一个???
直接set不就好啦。。
bzoj里面用set就能过。。不过洛谷里面的只能70分。
正解hash表。秒杀。。

#include <bits/stdc++.h>
using namespace std;
int head[133331],next[1926817+1],val[1926817+1],n,tmp,tot=0;
bool inst(int x);
void work();
int main()
{
    int Case;
    scanf("%d",&Case);
    while(Case--){
        work();
    }
    return 0;
}
void work(){
    memset(head,0,sizeof(head));
    memset(next,0,sizeof(next));
    memset(val,0,sizeof(val));
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&tmp);
        if(inst(tmp)){
            printf("%d ",tmp);
        }
    }
    printf("\n");
}
bool inst(int x){
    int t=x%133331;
    for(int i=head[t];i;i=next[i])
        if(val[i]==x)
            return false;
    val[++tot]=x;
    next[tot]=head[x];
    head[x]=tot;
    return true;
}

猜你喜欢

转载自www.cnblogs.com/onglublog/p/9859720.html
今日推荐