[UVA][Trie] 11286 - Conformity@Morris' Blog|PChome Online 人新台
2012-04-01 20:28:48| 人1,206| 回0 | 上一篇 | 下一篇

[UVA][Trie] 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 fromamong those available.

University administrators are uncomfortable with this situation, andtherefore wish to offer a conformity prize to frosh who choosethe most popular combination of courses. How many frosh will winthe prize?

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

The popularity of a combination is the number of frosh selectingexactly the same combination of courses. A combination of coursesis considered most popular if no other combination has higherpopularity. For each line of input, you should output a single linegiving the total number of students taking some combination of courses thatis 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Trie {
int n;
int link[10];
}Node[200000];
int TrieSize;
void insertTrie(const char* str) {
static int i, idx;
idx = 0;
for(i = 0; str[i]; i++) {
if(Node[idx].link[str[i]-'0'] == 0) {
TrieSize++;
memset(&Node[TrieSize], 0, sizeof(Node[0]));
Node[idx].link[str[i]-'0'] = TrieSize;
}
idx = Node[idx].link[str[i]-'0'];
}
Node[idx].n ++;
}
int max, maxNum;
void findAns(int now) {
if(Node[now].n != 0) {
if(max == Node[now].n) {
maxNum += Node[now].n;
} else if(max < Node[now].n){
max = Node[now].n;
maxNum = max;
}
}
int i;
for(i = 0; i < 10; i++) {
if(Node[now].link[i] != 0) {
findAns(Node[now].link[i]);
}
}
}
int cmp(const void *i, const void *j) {
return *(int *)i - *(int *)j;
}
int main() {
int n, A[5];
char buf[20];
while(scanf("%d", &n) == 1 && n) {
TrieSize = 0;
memset(&Node[0], 0, sizeof(Node[0]));
while(n--) {
scanf("%d %d %d %d %d", &A[0], &A[1], &A[2], &A[3], &A[4]);
qsort(A, 5, sizeof(int), cmp);
sprintf(buf, "%d%d%d%d%d", A[0], A[1], A[2], A[3], A[4]);
insertTrie(buf);
}
max = 0, maxNum = 0;
findAns(0);
printf("%d\n", maxNum);
}
return 0;
}


台: Morris
人(1,206) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][Map] 11286 - Conformity
此分上一篇:[UVA][Trie] 10226 - Hardwood Species

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86