UVa 11286-conformity

Source: Internet
Author: User



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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.