POJ 3640

题意:n个学生的5门课程,找出课程组合出现次数最多的,输出选出现次数最多课程组合(不一定一个)的学生人数。

题解:对5门课程排序,然后hash判重,接着统计即可。

View Code
 1 #include<cstring>
 2 #include<algorithm>
 3 #include<string>
 4 #include<map>
 5 #include<cstdio>
 6 using namespace std;
 7 const int mod=1000000;
 8 long long hash[mod];
 9 int tot[mod];
10 long long po[10005];
11 int getkey(long long x)
12 {
13     int i,y=x%mod;
14     for(i=1; hash[y]!=x&&hash[y]!=-1; i++)
15     {
16         y=y+i*i;
17         if(y>=mod)
18             y%=mod;
19     }
20     return y;
21 }
22 int main()
23 {
24     int n;
25     while(scanf("%d",&n),n)
26     {
27         memset(hash,-1,sizeof(hash));
28         memset(tot,0,sizeof(tot));
29         int ans=0;
30         for(int i=0; i<n; i++)
31         {
32             long long tp=0;
33             int x[10];
34             for(int j=0; j<5; j++)
35                 scanf("%d",&x[j]);
36             sort(x,x+5);
37             for(int j=0;j<5;j++)
38                 tp=tp*1000+x[j];
39             int pos=getkey(tp);
40             ans=max(ans,++tot[po[i]=pos]);
41             hash[pos]=tp;
42         }
43         int cnt=0;
44         for(int i=0;i<n;i++)
45         {
46             if(tot[po[i]]==ans)
47                 cnt++;
48         }
49         printf("%d\n",cnt);
50     }
51     return 0;
52 }

转载于:https://www.cnblogs.com/tmeteorj/archive/2012/10/02/2710285.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值