【hash】Conformity


Conformity
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2559 Accepted: 785

Description

Frosh commencing their studies at Waterloo have diverse interests, as evidenced by their desire to take various combinations of courses from among those available.

University administrators are uncomfortable with this situation, and therefore wish to offer a conformity prize to frosh who choose one of the most popular combinations of courses. How many frosh will win the prize?

Input

The input consists of several test cases followed by a line containing 0. Each test case begins with an integer 1 ≤ n ≤ 10000, the number of frosh. For each frosh, a line follows containing the course numbers of five distinct courses selected by the frosh. Each course number is an integer between 100 and 499.

The popularity of a combination is the number of frosh selecting exactly the same combination of courses. A combination of courses is considered most popular if no other combination has higher popularity.

Output

For each line of input, you should output a single line giving the total number of students taking some combination of courses that is most popular.

Sample Input

3
100 101 102 103 488
100 200 300 101 102
103 102 101 488 100
3
200 202 204 206 208
123 234 345 456 321
100 200 300 400 444
0

Sample Output

2
3



原来说这题是用到hash的,所以做了下,结果发现主要的部分还是排序。
给出每个学生的选课组合,当与其他学生选课组组合相同时  受欢迎度加一
求最受欢迎的选课组合的人数是多少 .

#include<cstdio>
#include<algorithm>
using namespace std;
long long num[10001];
int main()
{
    int n,x[5];
    __int64 ans;
    for(;scanf("%d",&n),n;)
    {
        for(int i=0;i<n;++i)
        {
            ans=0;
            scanf("%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&x[4]);
            sort(x,x+5);
            for(int j=0;j<5;++j)
               ans=ans*1000+x[j];
            num[i]=ans;
        }
        sort(num,num+n);
        int maxx=0,flag=0;
        for(int i=0,j=0;i<n;j=0)
        {
                for(j=i;j<n&&num[i]==num[j];++j);
                if(maxx<(j-i))
                   maxx=(j-i);
                i=j;
        }
        for(int i=0,j=0;i<n;j=0)
        {
                for(j=i;j<n&&num[i]==num[j];++j);
                if(maxx==(j-i))
                   flag+=maxx;
                i=j;
        }
        printf("%d\n",flag);
    }
    return 0;
}

来源: http://blog.csdn.net/ACM_Ted

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值