zoukankan      html  css  js  c++  java
  • bzoj 2761: [JLOI2011]不重复数字【hash】

    map会T,双hash会冲突……于是非酋写了个三hash

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int N=1000005,mod1=739391,mod2=967543,mod3=1000003;
    int T,n;
    bool h1[N],h2[N],h3[N];
    int read()
    {
        int r=0,f=1;
        char p=getchar();
        while(p>'9'||p<'0')
        {
            if(p=='-')
                f=-1;
            p=getchar();
        }
        while(p>='0'&&p<='9')
        {
            r=r*10+p-48;
            p=getchar();
        }
        return r*f;
    }
    int main()
    {
        T=read();
        while(T--)
        {
            n=read();
            memset(h1,0,sizeof(h1));
            memset(h2,0,sizeof(h2));
            memset(h3,0,sizeof(h3));
            for(int i=1;i<=n;i++)
            {
                int x=read(),x1=(x%mod1+mod1)%mod1,x2=(x%mod2+mod2)%mod2,x3=(x%mod3+mod3)%mod3;
                if(!h1[x1]||!h2[x2]||!h3[x3])
                {
                    h1[x1]=1,h2[x2]=1,h3[x3]=1;
                    printf("%d ",x);
                }
            }
            puts("");
        }
        return 0;
    }
    
  • 相关阅读:
    spring mvc 分页
    get/post时中文乱码问题的解决办法
    mysql-day01
    servler配置
    idea
    springMvc 核心配置
    ServletRequest面试题
    Servlet面试题
    Http面试题
    测试文件
  • 原文地址:https://www.cnblogs.com/lokiii/p/9712975.html
Copyright © 2011-2022 走看看