zoukankan      html  css  js  c++  java
  • hash

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #include<ctime>
    #include<cstring>
    #define inf 2147483647
    #define For(i,a,b) for(register long long i=a;i<=b;i++)
    #define p(a) putchar(a)
    #define g() getchar()
    #define MOD1 1e9+7
    #define MOD2 1e9+9
    #define base 31
    //by war
    //2017.10.13
    using namespace std;
    long long n;
    char c[10000];
    struct has
    {
        long long one;
        long long two;
        bool operator<(const has&a)const
        {
            return one<a.one;
        }
    }ha[10010];
    void in(long long &x)
    {
        long long y=1;
        char c=g();x=0;
        while(c<'0'||c>'9')
        {
        if(c=='-')
        y=-1;
        c=g();
        }
        while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
        x*=y;
    }
    void o(long long x)
    {
        if(x<0)
        {
            p('-');
            x=-x;
        }
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    long long hash(long long MOD)
    {
        long long ans=0;
        long long len=strlen(c);
        For(i,0,len-1)
        ans=(ans*base+(long long)c[i])%MOD;
        return ans;
    }
    
    int main()
    {
        long long ans=0;
        in(n);
        For(i,1,n)
        {
            scanf("%s",&c);
            ha[i].one=hash(MOD1);
            ha[i].two=hash(MOD2);
        }
        sort(ha+1,ha+n+1);
        For(i,2,n)
        if(ha[i].one!=ha[i-1].one||ha[i].two!=ha[i-1].two)
        ans++;
        o(++ans);
         return 0;
    }

     一定要排序,让相同的都靠在一起,这样才可以判重。

  • 相关阅读:
    python爬虫如何提高效率
    对 js加密数据进行爬取和解密
    爬虫之数据解析
    requests模块的基本使用
    python的零碎知识
    Django中多表关联的展示问题:
    ModelForm的基本用法:
    websocket的应用---Django
    DOM
    BOM
  • 原文地址:https://www.cnblogs.com/war1111/p/7661884.html
Copyright © 2011-2022 走看看