Title: Elective system, each candidate 5 courses, if many people choose the same 5 courses think this combination is more popular,
The selection of the most popular course combinations is now required.
Analysis: Data structure, STL. Sort each set of data first, and then use map statistics to solve it.
(You can also use a hash table or use a long long to compress the sorting statistics)
Description: If there are a lot of people in the mix, it's all counted together.
#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;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVa 11286-conformity