UVa 11286 - Conformity

来源:互联网 发布:彩票数据分析软件 编辑:程序博客网 时间:2024/06/05 06:38

题目:选课系统,每个人选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;}


0 0
原创粉丝点击