Poj 2092 grandpa is famous]

Source: Internet
Author: User
Link: http://poj.org/problem? Id = 2092 http://acm.hust.edu.cn/vjudge/contest/view.action? Cid = 27454 # Problem/dgrandpa is famous
Time limit:2000 ms   Memory limit:30000 K
Total submissions:7210   Accepted:3650

Description

The whole family was excited by the news. everyone knew grandpa had been an extremely good bridge player for decades, but when it was announced he wocould be in the Guinness Book of World Records as the most successful bridge player ever, whow, that was astonishing!
The International Bridge Association (IBA) has maintained, for several years, a weekly ranking of the best players in the world. considering that each appearance in a weekly ranking constitutes a point for the player, Grandpa was nominated the best player ever
Because he got the highest number of points.
Having has friends who were also competing against him, Grandpa is extremely curious to know which player (s) took the second place. since the BA rankings are now available in the Internet he turned to you for help. he needs a program which, when given a list
Of weekly rankings, finds out which player (s) got the second place according to the number of points.

Input

The input contains several test cases. players are identified by integers from 1 to 10000. the first line of a test case contains two integers n and m indicating respectively the number of rankings available (2 <= n <= 500) and the number of players in each
Ranking (2 <= m <= 500 ). each of the next n lines contains the description of one weekly ranking. each description is composed by a sequence of M integers, separated by a blank space, identifying the players who figured in that weekly ranking. you can assume
That:
  • In each test case there is exactly one best player and at least one second best player,
  • Each weekly ranking consists of m distinct player identifiers.

The end of input is indicated by N = m = 0.

Output

For each test case in the input your program must produce one line of output, containing the identification number of the player who is second best in number of appearances in the rankings. if there is a tie for second best, print the identification numbers
Of all second best players in increasing order. Each identification number produced must be followed by a blank space.

Sample Input

4 520 33 25 32 9932 86 99 25 1020 99 10 33 8619 33 74 99 323 62 34 67 36 79 93100 38 21 76 91 8532 23 85 31 88 10 0

Sample output

32 331 2 21 23 31 32 34 36 38 67 76 79 88 91 93 100

Source


Code:

/*************************************** * ********************* Daccepted284 kb204 MSC ++ 1604 B: the first row gives you n and m the remaining n rows of M columns, and gives you n * m number to find the number of all occurrences of the second plus, and output in ascending order. **************************************** * *********************/# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; const int maxn = 10000 + 10; int A [maxn]; struct node {int num; int index;} node [maxn]; bool CMP (node A, Node B) {if (. num = B. num) return. index <B. index; else return. num> B. num;} int main () {int n, m; while (scanf ("% d", & N, & M )! = 0) {If (n = 0 & M = 0) break; int X; int max = 0; For (INT I = 0; I <maxn; I ++) {A [I] = 0; node [I]. num = 0; node [I]. index = 0 ;}int n = N * m; For (INT I = 0; I <n; I ++) {scanf ("% d", & X ); A [x] ++; max = max (max, x);} n = MAX + 1; // printf ("max = % d \ n", max ); int J = 0; For (INT I = 1; I <n; I ++) {if (a [I]! = 0) {node [J]. num = A [I]; node [J]. index = I; j ++ ;}} sort (node, node + J, CMP); n = J; int S = node [0]. num; // printf ("S1 = % d \ n", S); int Index = 0; For (INT I = 0; I <n; I ++) {If (node [I]. num <s) {S = node [I]. num; Index = I; break; }}// printf ("S2 = % d \ n", S); For (INT I = index; I <N; I ++) {If (node [I]. num = s) {printf ("% d", node [I]. index);} else if (node [I]. num> S) break;} printf ("\ n");} return 0 ;}

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.