POJ 2092 Grandpa is Famous 水

Grandpa is Famous

Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 7985   Accepted: 4007

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

South America 2004

1A

ACcode:

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 100
using namespace std;
struct m{
    int id;
    int time;
}me[10000+5];
int isused[10000+5];
int is[10000+5];
bool cmp(m a,m b){
    if(a.time!=b.time)return a.time>b.time;
    return a.id<b.id;
}
int main(){
    int n,m,t,count;
    while(scanf("%d%d",&n,&m)!=EOF&&(n||m)){
        count=0;
        memset(isused,0,sizeof(isused));
        memset(is,0,sizeof(is));
        for(int i=0;i<n;++i){
            for(int j=0;j<m;++j){
                scanf("%d",&t);
                if(isused[t]==0){
                    //printf("yes!\n");
                    me[count].id=t;
                    me[count].time=1;
                    isused[t]=11;
                    is[t]=count;
                    count++;
                }else {
                    me[is[t]].time++;
                }
            }
        }

       sort(me,me+count,cmp);
       printf("%d",me[1].id);
       for(int i=2;;++i){
            if(me[i].time!=me[i-1].time)break;
            printf(" %d",me[i].id);
       }
       putchar('\n');
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-09 13:26:27

POJ 2092 Grandpa is Famous 水的相关文章

POJ 1228 Grandpa&#39;s Estate [稳定凸包]

Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13112   Accepted: 3697 Description Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one

poj 1228 Grandpa&#39;s Estate (稳定凸包问题)

---恢复内容开始--- 题意:你的长辈给你留了块土地,然而这块土地是以一些钉子来界定的,题目要做的就是给你一堆钉子的坐标(也就是凸包上部分的点),然后问你能不能唯一确定这块土地 //不得不说知道题意后一脸懵逼.. 知识:稳定凸包 所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点. 举一个不稳定的例子 为什么说它不稳定呢?因为他可以加点来得到更大的凸包 那什么样子是稳定的呢? 因此我们可以知道当一个凸包稳定时,凸包的每条边上都要有至少三个点,若只有两

POJ 1228 Grandpa&#39;s Estate --深入理解凸包

题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类似下面的语句: for(int i=0;i<n;i++) { while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--; ch[m++] = p[i]; } 这样的话,求出来就是最简凸包,即点数尽量少的凸包,因

poj 1228 Grandpa&#39;s Estate(凸包)

Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11508   Accepted: 3188 Description Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one

poj 1579 Moving Tables(水)

Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, a m = a m−1 − m if the rsulting a m is positive and not already in the sequence, otherwise a m = am−1 + m. The first few numbers in the Recaman's Sequence is 0, 1, 3, 6, 2, 7, 13, 2

poj 3031 Big Christmas Tree(水spfa)

http://poj.org/problem?id=3013 题意: Because of a technical difficulty, price of an edge will be (sum of weights of all descendant nodes) × (unit price of the edge).这句话一直没看懂.后面还以为是最小生成树. 正确题意是:给一个无向图,计算每个点到1节点的最短路径(dis[i]) * 每个节点的weights之和. 注意:边权值等要用__

POJ 1274 The Perfect Stall 水二分匹配

题目链接:点击打开链接 嘿嘿 #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<vector> #include<queue> #include<functional> #define N 2011 using namespace std; int lef[N], pn;//lef[v]表示Y集的点v 当前连接

POJ 1228 Grandpa&#39;s Estate (稳定凸包)

读懂题意很关键,输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点. 首先来了解什么是稳定的凸包. 比如有4个点: 这四个点是某个凸包上的部分点,他们连起来后确实还是一个凸包,但是它们不是稳定的, 我们发现,当凸包上存在一条边上的点只有端点两个点的时候,这个凸包不是稳定的,因为它可以在这条边外再引入一个点,构成一个新的凸包.但一旦一条边上存在三个点,那么不

POJ 3030. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13136   Accepted: 9077 Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of malicious software which teenagers may use to fool their friends.