B. F1 Champions
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion
of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use
for compare.

Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing
number of second, third, forth, and so on, places.

You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.

Input

The first line contain integer t (1 ≤ t ≤ 20),
where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 ≤ n ≤ 50)
on a line of itself, where n is the number of clasified drivers in the given race. After thatn lines
follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50
characters. Comparing of names should be case-sensetive.

Output

Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.

Examples
input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
output
Vettel
Hamilton
input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
output
Prost
Prost

结构体排序
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <string> using namespace std;
int n,m;
struct Node
{
int score;
int r[55];
string name;
}a[1005];
int cmp1(Node a,Node b)
{
if(a.score==b.score)
{
for(int i=1;i<50;i++)
{
if(a.r[i]==b.r[i])
continue;
return a.r[i]>b.r[i];
}
}
return a.score>b.score;
}
int cmp2(Node a,Node b)
{
if(a.r[1]==b.r[1])
{
if(a.score==b.score)
{
for(int i=2;i<50;i++)
{
if(a.r[i]==b.r[i])
continue;
return a.r[i]>b.r[i];
}
}
return a.score>b.score;
}
return a.r[1]>b.r[1];
}
map<string,int> mm; int num[55]={0,25,18,15,12,10,8,6,4,2,1};
int main()
{
scanf("%d",&n);
string s;
int cnt=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&m);
for(int j=1;j<=m;j++)
{
cin>>s;
if(!mm.count(s))
mm[s]=cnt++;
a[mm[s]].score+=num[j];
a[mm[s]].r[j]++;
a[mm[s]].name=s;
}
}
sort(a,a+cnt,cmp1);
cout<<a[0].name<<endl;
sort(a,a+cnt,cmp2);
cout<<a[0].name<<endl;
return 0;
}

CodeForces 24B F1 Champions(排序)的更多相关文章

  1. 24B F1 Champions

    传送门 题目 Formula One championship consists of series of races called Grand Prix. After every race driv ...

  2. Codeforces 510C (拓扑排序)

    原题:http://codeforces.com/problemset/problem/510/C C. Fox And Names time limit per test:2 seconds mem ...

  3. E - E CodeForces - 1100E(拓扑排序 + 二分)

    E - E CodeForces - 1100E 一个n个节点的有向图,节点标号从1到n,存在m条单向边.每条单向边有一个权值,代表翻转其方向所需的代价.求使图变成无环图,其中翻转的最大边权值最小的方 ...

  4. CodeForces 721C Journey(拓扑排序+DP)

    <题目链接> 题目大意:一个DAG图有n个点,m条边,走过每条边都会花费一定的时间,问你在不超过T时间的条件下,从1到n点最多能够经过几个节点. 解题分析:对这个有向图,我们进行拓扑排序, ...

  5. Divide by three, multiply by two CodeForces - 977D (思维排序)

    Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, a ...

  6. Selling Souvenirs CodeForces - 808E (分类排序后DP+贪心)

    E. Selling Souvenirs time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Cinema CodeForces - 670C (离散+排序)

    Moscow is hosting a major international conference, which is attended by n scientists from different ...

  8. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  9. CodeForces - 919D Substring (拓扑排序+dp)

    题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...

随机推荐

  1. HDU 1016:Prime Ring Problem

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. Python中使用UUID

    import uuid ... ... print uuid.uuid1() 生成的方法还有uuid2..n,具体参见官网LINK,包括参数细则

  3. 复现IIS6.0远程命令执行漏洞

    出这个漏洞有一定时间了,一直没测试,因为知道这个漏洞有条件的,好吧,顺便感谢royal大佬今天晚上日内网的指点. 漏洞要求: 开启Webdav PS:不想刚拿下的内网服务器一下权限掉了,又不想放xx远 ...

  4. 关于love2d教程的更新

    实在抱歉,每周工作六天,一天13小时以上,周日想休息一下,love2d的估计一个月一篇都很难做到了. 三个月后公司的项目应该做完了,那时应该有时间了. love2d估计快发布0.9了,改动应该不是很大 ...

  5. 递归删除子目录下所有.la后缀文件

    删除当前目录及其子目录下的后缀名.la的所有文件 find ./ -name '*.la' | xargs rm -f

  6. MongoDB(一):关系型数据库和非关系型数据库

    一.关系型数据库 1.概念 关系型数据库:是指采用了关系模型来组织数据的数据库,是目前各类数据库中使用最为广泛的数据库系统.简单的说,关系模型指的就是二维表格模型,一个关系型数据库就是由二维表及其之间 ...

  7. AJAX的中文乱码问题

    /***********本人原创,欢迎转载,转载请保留本人信息*************/作者:wallimn电邮:wallimn@sohu.com博客:http://blog.csdn.net/wa ...

  8. 遍历一个Set的方法只有一个:迭代器(interator)

    Set-HashSet实现类: 遍历一个Set的方法只有一个:迭代器(interator). HashSet中元素是无序的(这个无序指的是数据的添加顺序和后来的排列顺序不同),而且元素不可重复. 在O ...

  9. 解决spring boot中rest接口404,500等错误返回统一的json格式

    在开发rest接口时,我们往往会定义统一的返回格式,列如: { "status": true, "code": 200, "message" ...

  10. hdu 3905(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3905 思路:dp[i][j]表示前i分钟,睡了j分钟收获的的最大价值,并记tmp_dp[i][j]为从 ...