/*
http://poj.org/problem?id=2092
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#problem/D
Grandpa is Famous
Time Limit: 2000MS Memory Limit: 30000K
Total Submissions: 7228 Accepted: 3653
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
Accepted 244 KB 172 ms C++ 919 B 2013-07-28 20:40:07
解析:
题意:给出一组数据,将出现次数排名第二的数据按照其值递增的顺序输出
思路:将数据出现的次数进行排序后输出
*/
http://poj.org/problem?id=2092
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#problem/D
Grandpa is Famous
Time Limit: 2000MS Memory Limit: 30000K
Total Submissions: 7228 Accepted: 3653
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
Accepted 244 KB 172 ms C++ 919 B 2013-07-28 20:40:07
解析:
题意:给出一组数据,将出现次数排名第二的数据按照其值递增的顺序输出
思路:将数据出现的次数进行排序后输出
*/
#include<stdio.h>
#include<string.h>
#include<stack>
#include<vector>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=10000+10;
struct people
{ int po;
int id;
}p[maxn];
bool cmp(people p1,people p2)
{
return p1.po>p2.po||(p1.po==p2.po&&p1.id<p2.id);
}
int main()
{
int n,m;
int i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
int a;
memset(p,0,sizeof(p));
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
scanf("%d",&a);
p[a].po++;
p[a].id=a;
}
sort(p,p+maxn,cmp);
j=0;
while(p[j].po==0)
{j++;}
int t=p[j+1].po,ans=0;
for(i=j+1;i<maxn;i++)
{
if(p[i].po==t)
ans++;
}
for(i=j+1;i<maxn;i++)
{
if(p[i].po==t)
{ ans--;
printf("%d",p[i].id);
if(ans)
printf(" ");
else
printf("\n");
}
if(ans==0)
break;
}
}
return 0;
}

本文深入探讨了编程技术领域的多个关键主题,包括前端开发、后端开发、移动开发、游戏开发等细分领域,旨在为读者提供全面的技术洞察与实践指导。文章详细解析了各领域内的核心技术与应用实例,帮助开发者深化理解并提升技能。
366

被折叠的 条评论
为什么被折叠?



