Monday, December 7, 2015

UVa 11286 - Conformity

// UVa 11286 - Conformity

#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

struct selection {
	int a[5];
};

bool operator <(const selection & a, const selection & b) {
	for (int j = 0; j < 5; j++)
		if (a.a[j] != b.a[j])
			return a.a[j] < b.a[j];
	return false;
}

bool operator ==(const selection & a, const selection & b) {
	for (int j = 0; j < 5; j++)
		if (a.a[j] != b.a[j])
			return false;
	return true;
}

int main() {
	int n;
	cin >> n;
	while (n) {
		selection c[10000];
		map<selection, int> m;
		int max = 0;
		int combs = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 5; j++)
				cin >> c[i].a[j];
			sort(c[i].a, c[i].a + 5);
			m[c[i]]++;
			if (m[c[i]] > max) {
				max = m[c[i]];
				combs = 1;
			} else if (m[c[i]] == max)
				combs++;
		}
		cout << combs * max << endl;
		cin >> n;
	}

	return 0;
}

No comments:

Post a Comment