• nupt1207(重数问题)


    1.统计重数及次数。

    2.hash。%p,若冲突,则向后移动。

    ******************************

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn=5000000;
    const int p=1200007;
    struct Node
    {
        int cnt,x;
    }hash[maxn];
    int main()
    {
        //freopen("in","r",stdin);
        int n;
        while(~scanf("%d",&n))
        {
            int x;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&x);
                int tmp=x%p;
                if(hash[tmp].cnt==0)hash[tmp].cnt++,hash[tmp].x=x;
                else if(hash[tmp].x==x)hash[tmp].cnt++;
                else
                {
                    while((hash[tmp].cnt!=0) && (hash[tmp].x!=x))
                        tmp++;
                    if(hash[tmp].cnt)hash[tmp].cnt++;
                    else hash[tmp].cnt++,hash[tmp].x=x;
                }
            }
            if(n==1)
            {
                printf("%d %d ",x,1);
                continue;
            }
            int ans1=0,ans2=0;
            for(int i=0;i<p+p;i++)
            {
                if(hash[i].cnt>ans2)
                    ans2=hash[i].cnt,ans1=hash[i].x;
                else if(hash[i].cnt==ans2 && ans1>hash[i].x)
                            ans1=hash[i].x;
            }
            printf("%d %d ",ans1,ans2);
        }
        return 0;
    }

    ******************************

  • 相关阅读:
    XML与JSON的对比
    WPF dataGrid下的ComboBox的绑定
    WPF 导出Excel(合并单元格)
    WPF x:key和x:name用法
    WPF Canvas
    WPF Visibility属性用法
    AxInterop.ShockwaveFlashObjects.dll 问题
    BadImageFormatException,未能加载正确的程序集XXX的解决办法
    inner join ,left join ,right join区别
    Mac系统下php.ini的位置
  • 原文地址:https://www.cnblogs.com/MobileRobot/p/3775122.html
Copyright © 2020-2023  润新知