zoukankan      html  css  js  c++  java
  • cogs 1176. [郑州101中学] 月考

    二次联通门 : cogs 1176. [郑州101中学] 月考

    /*
        cogs 1176. [郑州101中学] 月考
        
        字符串hash + 二分查找 
        
        复杂度O(N log N * K)
        其实用map可以轻松跑过 
        
        又学了个新姿势
        algorithm库中的binary_search 提供了二分查找的功能 
    */
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    
    #define Mod 26
    
    void read (int &now)
    {
        register char word = getchar ();
        for (now = 0; word < '0' || word > '9'; word = getchar ());
        for (; word >= '0' && word <= '9'; now = now * 10 + word - '0', word = getchar ());
    }
    
    int N, M;
    
    unsigned long long hash_number;
    
    #define Max 300
    char line[Max];
    
    long long hash[Max * 2000];
    
    int main (int argc, char *argv[])
    {
        freopen ("mtest.in", "r", stdin);
        freopen ("mtest.out", "w", stdout);
        
        read (N);
        
        for (register int i = 1, Len; i <= N; i ++)
        {
            scanf ("%s", line);
            Len = strlen (line);
            hash_number = 1;
            for (int pos = 0; pos < Len; pos ++)
                hash_number = hash_number * Mod + line[pos];
            hash[i] = hash_number;
        }
        std :: sort (hash + 1, hash + 1 + N);
        read (M);
        int Answer = 0;
        for (register int Len; M --; )
        {
            scanf ("%s", line);
            Len = strlen (line);
            hash_number = 1;
            for (int pos = 0; pos < Len; pos ++)
                hash_number = hash_number * Mod + line[pos];
            if (std :: binary_search (hash + 1, hash + 1 + N, hash_number))
                Answer ++;
        }
        printf ("%d", Answer);
        return 0;
    }
  • 相关阅读:
    抽样调查
    一次项目上线发布的感想
    Nginx failing to load CSS and JS files (MIME type error)
    securecrt-active
    golang-http-post
    remove-weknow-ac from mac chrome
    批量写入redis
    golang 修改数组中结构体对象的值的坑
    golang使用json生成结构体
    json定义
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/7197120.html
Copyright © 2011-2022 走看看