poj 2092 Grandpa is Famous

来源:互联网 发布:gif编辑文字软件 编辑:程序博客网 时间:2024/05/29 19:11
Grandpa is Famous
Time Limit: 2000MS Memory Limit: 30000KTotal Submissions: 7524 Accepted: 3778

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 would 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.
一个消息玲全家人都很兴奋。每个人都知道爷爷曾经是一个非常好的桥梁球员,几十年了,但它被宣布,他将是世界纪录的吉尼斯最成功的桥梁的球员,whow,这是非常惊人的! 
国际桥梁协会(IBA)一直在刷新,几年来,最好的球员在世界上每周排名。考虑到在每周的排名都是分数排名,爷爷被提名有史以来最好的球员,因为他得到了最高分。
Having many friends who were also competing against him, grandpa is extremely curious to know which player(s) took the second place. Since the IBA 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: 
输入包含若干测试用例。球员由一个整数标识从1到10000。测试用例的第一行包含两个整数N和M分别表示排名的(2<= N<=500)的数量和球员的数量在各个排名上(2<= M<=500)。接下来的N行中包含的一个每周排名的说明。每个描述是一个序列包含M个整数,用空格隔开,确定谁进入了周排名。你可以假设: 
  • 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.每个每周的排名由M个不同的球员标识。

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

South America 2004

读完题自己乱套了,后来发现就是谁上榜次数多谁就牛逼。。。
计数排序1a水过,因为数据量小,所以就这么凑合过了。。。。。。
其中if后面加分号查了半天,黑历史莫提莫提。。。。
#include <iostream>#include<algorithm>#include <stdio.h>#include <string.h>#include <math.h>using namespace std;int main(){    int i, j, N, M;    int player_num;    int max_num, max_id, sec_num;    int map_m[11111];    freopen("in.txt", "r", stdin);//    freopen("out.txt", "w", stdout);    while(scanf("%d%d", &N, &M) && !(N == 0 && M == 0)){        memset(map_m, 0, sizeof(map_m));        max_num = -1;        max_id = -1;        for (i = 0;i < N;++ i){            for (j = 0;j < M;++ j){                scanf("%d", &player_num);//                printf("%d ", player_num);                map_m[player_num] ++;                if (player_num > max_id)                    max_id = player_num;                if (map_m[player_num] > max_num)                    max_num = map_m[player_num];            }        }//        printf("\n");//        printf("max_id = %d, max_num = %d\n", max_id, max_num);        sec_num = -1;        for (i = 0;i <= max_id;++ i){//            if (map_m[i] != 0)//                printf("map_m[%d] = %d\n", i, map_m[i]);            if (map_m[i] < max_num && map_m[i] > sec_num){                sec_num = map_m[i];            }        }        for (i = 0;i <= max_id;++ i){            if (map_m[i] < 1)                continue;            else if (map_m[i] == sec_num){                printf("%d ", i);            }        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击