Grandpa is Famous
Time Limit: 2000MS  Memory Limit: 30000K
Total Submissions: 7256  Accepted: 3670

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.
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:

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 5
20 33 25 32 99
32 86 99 25 10
20 99 10 33 86
19 33 74 99 32
3 6
2 34 67 36 79 93
100 38 21 76 91 85
32 23 85 31 88 1
0 0
Sample Output

32 33
1 2 21 23 31 32 34 36 38 67 76 79 88 91 93 100
Source

题意:爷爷打桥牌很厉害,拿得冠军。但是他还想知道,除了他,那些选手是第二(或者并列第二)。现已知每场比赛,有名次的选手的编号,请根据获得名次的次数的多少判定选手的排名,求第二(或者并列第二)的选手的编号。

#include <stdio.h>
#define MAX_LEN 10100
int sz[MAX_LEN];
int main()
{
 int n,m;
 while(scanf("%d %d",&n,&m),n||m)
 {
  int i,j,a,b=0;  
  memset(sz,0,sizeof(sz));
  for(i=0;i<n;i++)
  for(j=0;j<m;j++)
  {
   scanf("%d",&a);
   sz[a]++;
  }
  for(i=1;i<MAX_LEN;i++)
  {
   if(sz[i]==0)
   continue;
   else if(sz[i]>sz[0])
   sz[0]=sz[i];
  }
  for(i=1;i<MAX_LEN;i++)
  {
   if((sz[i]==sz[0])||(sz[i]==0))
   continue;
   else if(sz[i]>b)
   b=sz[i];
  }
  for(i=1;i<MAX_LEN;i++)
  {
   if(sz[i]==b)
   printf("%d ",i);
  }
  printf("\n");
 }
 return 0;
}

【ACM】poj_2092_Grandpa is Famous_201308021920的更多相关文章

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  3. 【ACM】魔方十一题

    0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...

  4. 【ACM】那些年,我们挖(WA)过的最短路

    不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...

  5. 【ACM】不要62 (数位DP)

    题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...

  6. 【Acm】八皇后问题

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...

  7. 【ACM】hud1166 敌兵布阵(线段树)

    经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...

  8. 【acm】杀人游戏(hdu2211)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others)    M ...

  9. 【ACM】How many prime numbers

    http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=2 #inclu ...

随机推荐

  1. DirectFB学习之移植到nuc972平台 标签: DirectFBlinux图形加速驱动【转】

    本文转载自:http://blog.csdn.net/jxgz_leo/article/details/70137304 [nuc972开发板购买地址,感谢支持](https://shop102749 ...

  2. hdu 1754(单点更新 ,区间最大值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. Human Gene Functions(dp)

    http://poj.org/problem?id=1080 #include <stdio.h> #include <stdlib.h> #include <strin ...

  4. hihoCoder 1187

    今天BC爆0了....但是日子还是要过的....要回学校毕业了~~大学就这么“荒废”了. 这个是hihoCoder的1187,比较基础的一道题. 题目链接: http://hihocoder.com/ ...

  5. LeetCode.3-最长无重复字符子串(Longest Substring Without Repeating Characters)

    这是悦乐书的第341次更新,第365篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第2题Longest Substring Without Repeating Cha ...

  6. Run as ant build每次都执行两次-问题解决

    在Eclipse里面,运行ant,整个测试流程总是执行两遍,其几天试了下在DOS命令行直接调用ant, 结果发现只执行了一次,并且内存消耗好像也没那么大了,估计是eclipse自己的问题.问题解决了, ...

  7. ASP.NET的Eval方法和Bind方法的区别

    Eval是只读的方法(单向数据在邦定),所邦定的内容为不会提交回服务器. 比如图书的ISBN,并不想让用户做任何修改,可以使用<%# Eval('ISBN').TOString().Trim() ...

  8. My97DatePicker 动态设置有效/无效日期

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  9. windows phone传感器

    Windows phone中的传感器主要包括加速计传感器.罗盘传感器.陀螺仪传感器等 加速计传感器 Accelerometer类是加速传感器的接口,Accelerometer类位于Windows.De ...

  10. Visual Studio UI Automation 学习(三)

    昨天了解到UI Automation是微软的.Net Framework框架里的4个DLL文件,可以在Visual studio里写代码时引入引用和引用命名空间.然后去写自动化代码. 今天本来是跟着一 ...