标签:
题目:选课系统,每个人选5门课,如果很多人选择相同5门课认为这个组合比较热门,
现在要求出选择最热门课程组合的选择人数。
分析:数据结构,STL。对每组数据先排序,然后利用map统计求解即可。
(也可以使用hash表或者利用long long压缩排序统计)
说明:如果有很多人们组合,都算在一起。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <map>
typedef long long LL;
using namespace std;
int courses[5];
int main()
{
int n;
while (cin >> n && n) {
map<LL, int> Map;
int maxv = 1, count = 0;
for (int t = 0; t < n; ++ t) {
for (int i = 0; i < 5; ++ i)
cin >> courses[i];
sort(courses, courses+5);
LL value = 0LL;
for (int i = 0; i < 5; ++ i) {
value *= 1000;
value += courses[i];
}
maxv = max(maxv, Map[value] += 1);
}
for (map<LL, int>::iterator it = Map.begin(); it != Map.end(); ++ it)
if (it->second == maxv)
count += maxv;
cout << count << endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/mobius_strip/article/details/46981399