POJ 2092 Grandpa is Famous
Time Limit: 2000MS | Memory Limit: 30000K | |
Total Submissions: 7153 | Accepted: 3624 |
Description
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
- 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
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
题目大意:求出现次数第二多的数。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std; int nCount[]; int main()
{
int m, n;
int a;
while(scanf("%d%d", &m, &n) != EOF)
{
if (m == && n == )
{
break;
}
int index = ;
memset(nCount , , sizeof(nCount));
for(int i = ; i < m; i++)
{
for (int j = ; j < n; j++)
{
scanf("%d", &a);
nCount[a]++;
}
}
int max1 = -, max2 = -;
for (int i = ; i <= ; i++)
{
if (nCount[i] > max1)
{
max2 = max1;
max1 = nCount[i];
}
else
{
if (nCount[i] > max2)
{
max2 = nCount[i];
}
}
}
int nsum = ;
for (int i = ; i <= ; i++)
{
if (nCount[i] == max2)
{
if (nsum != )
{
printf(" %d", i);
}
else
{
nsum++;
printf("%d", i);
}
}
}
printf("\n");
}
return ;
}
POJ 2092 Grandpa is Famous的更多相关文章
- POJ 2092 Grandpa is Famous【水---找出现第二多的数】
链接: http://poj.org/problem?id=2092 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- Poj 2092 Grandpa is Famous(基数排序)
题目链接:http://poj.org/problem?id=2092 思路分析:先统计数据,在根据Count降序排序,Count相等时按照Num升序排序:再输出Count第二大的所有Num: 代码如 ...
- (使用STL自带的排序功能进行排序7.3.2)POJ 2092 Grandpa is Famous(结构体排序)
/* * POJ_2092.cpp * * Created on: 2013年11月1日 * Author: Administrator */ #include <iostream> #i ...
- POJ 1228 - Grandpa's Estate 稳定凸包
稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判 巨坑无比,调了很长时间= = //POJ 1228 //稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = ...
- POJ 1228 Grandpa's Estate(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- poj - 1228 - Grandpa's Estate
题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000). 题目链接:http://poj. ...
- POJ 1228 Grandpa's Estate 凸包 唯一性
LINK 题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变. 思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线 ...
- POJ 1228 Grandpa's Estate(凸包唯一性判断)
Description Being the only living descendant of his grandfather, Kamran the Believer inherited all o ...
- POJ 1228 Grandpa's Estate --深入理解凸包
题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...
随机推荐
- 【转】java的动态代理机制详解
java的动态代理机制详解 在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们 ...
- SQL 基本编程
定义变量 赋值 取值 分支语句 循环语句 定义变量 declare @变量 数据类型 //@必须带着 不然程序不知道变量是什么 不带@ 电脑会报错 例如 declare ...
- 远程linux服务器mysql数据库定期备份和删除
网上已经有部分关于Linux下定期备份mysql的方法,但是很多步骤不够详细,不适合新手,自己琢磨了很久,终于搞定了. 1.Linux服务器一般是ssh协议,如果本地也是Linux环境,可以直接通过s ...
- WPF中单选框RadioButton
单选框RadioButton的基本使用: <StackPanel Margin="10"> <Label FontWeight="Bold"& ...
- nuxt 头部引入js文件 第一次进入页面不加载js文件的解决方法
head () { return { title: '', meta: [ { hid: 'description', name: 'description', content: '' } ], sc ...
- for循环输出i为同一值的问题
使用闭包将变量i的值保护起来. //sava1:加一层闭包,i以函数参数形式传递给内层函数 for( var i=0; i<ps.length; i++ ) { (function(arg){ ...
- 数组初始化 和 vector初始化
] = {}; 整个数组都初始化为0 vector<); 整个vector初始化为1 如果你定义的vector是这样定义的: vector<int> B; 去初始化,千万不要用: ; ...
- Difference between x:Reference and x:Name
{x:Reference ...} -> returns just a reference of an object it doesn't create that "bridge&qu ...
- 转义字符 & sizeof & strlen
在定义了数组大小时: sizeof是运算符,表示编译时分配的空间大小,即数组定义的大小,char t[20] = "sfa".sizeof: 20; strlen: 3.在未定义数 ...
- shell脚本,alias别名命令用法。
[root@localhost ~]# alias alias cp='cp -i' alias mv='mv -i' alias rm='rm -i' [root@localhost ~]# [ro ...