zoukankan      html  css  js  c++  java
  • 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;
    }

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

  • 相关阅读:
    我的软件工程课目标
    软件工程课程的建议
    结对编程学习fault、error、failure三种状态
    结对编程项目的过程记录与收获
    “结对编程”之我见
    关于问卷调查
    我的软件工程课目标
    软件工程课程建议
    结对编程2
    结对编程之四则运算
  • 原文地址:https://www.cnblogs.com/MobileRobot/p/3775122.html
Copyright © 2011-2022 走看看