zoukankan      html  css  js  c++  java
  • hdu-1800(字符串hash)

    题目链接:传送门

    思路:

    就是找最多多少个扫帚,每个扫帚上有连续递增的序列,就是找一个最多重复数字的重复次数。

    由于是30位,每次用char*类型,然后用hash映射一下,排序找最多就行了。

    注意:

    (1)num最小也是1。

    (2)注意前导零。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn = 30030;
    const int INF = 0x7ffffff;
    typedef unsigned long long ULL;
    ULL base=133,a[maxn];
    char str[maxn];
    ULL Hash(char *s)
    {
        ULL ans=0,H=0;
        while(*s=='0') s++;
        while(*s)
        {
            H=H*base+(*s++);
        }
        return H&INF;
    }
    int main(void)
    {
        int n,i;
        while(~scanf("%d",&n))
        {
            for(i=0;i<n;i++)
            {
                scanf("%s",&str);
                a[i]=Hash(str);
            }
            sort(a,a+n);
            int num=1,tp=1;
            for(i=1;i<n;i++)
            {
                if(a[i]==a[i-1])
                {
                    tp++;
                    if(num<tp) num=tp;
                }
                else tp=1;
            }
            printf("%d
    ",num);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    【转载】Linux 内核启动时间分析
    hackbench
    c用户组函数
    c环境变量操作函数
    c网络接口套接字函数
    c信号处理函数
    c进程操作函数
    c文件内容操作函数
    c文件操作
    c数据结构和算法
  • 原文地址:https://www.cnblogs.com/2018zxy/p/10208576.html
Copyright © 2011-2022 走看看