24h購物| | PChome| 登入
2012-04-01 20:39:41| 人氣3,422| 回應0 | 上一篇 | 下一篇

[UVA][Map] 11286 - Conformity

推薦 0 收藏 0 轉貼0 訂閱站台

Problem B: Conformity

Frosh commencing their studies at Waterloo have diverse interests, as evidenced by their desire to take various combinations of courses from among those available.

University administrators are uncomfortable with this situation, and therefore wish to offer a conformity prize to frosh who choose the most popular combination of courses. How many frosh will win the prize?

The input consists of several test cases followed by a line containing 0. Each test case begins with an integer 1 ≤ n ≤ 10000, the number of frosh. For each frosh, a line follows containing the course numbers of five distinct courses selected by the frosh. Each course number is an integer between 100 and 499.

The popularity of a combination is the number of frosh selecting exactly the same combination of courses. A combination of courses is considered most popular if no other combination has higher popularity. For each line of input, you should output a single line giving the total number of students taking some combination of courses that is most popular.

Sample Input

3
100 101 102 103 488
100 200 300 101 102
103 102 101 488 100
3
200 202 204 206 208
123 234 345 456 321
100 200 300 400 444
0

Output for Sample Input

2
3

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

int main() {
int n, A[5];
char buf[20];
while(scanf("%d", &n) == 1 && n) {
string str;
map<string, int> record;
while(n--) {
scanf("%d %d %d %d %d", &A[0], &A[1], &A[2], &A[3], &A[4]);
sort(A, A+5);
sprintf(buf, "%d%d%d%d%d", A[0], A[1], A[2], A[3], A[4]);
str = buf;
record[str]++;
}
int max = 0, maxNum = 0;
for(map<string, int>::iterator i = record.begin(); i != record.end(); i++) {
if(i->second > max)
max = i->second, maxNum = 0;
if(i->second == max)
maxNum += max;
}
printf("%d\n", maxNum);
}
return 0;
}

台長: Morris
人氣(3,422) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Math][Stirling'sFormula] 1185 - Big Number
此分類上一篇:[UVA][Trie] 11286 - Conformity

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文