传送门

题目

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 that n 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
Note

It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.

题目大意

有许多场比赛,给出每场比赛的排名,有两种计分方式:先计分数再比各排名的数量和先比第一数量再比分数再比其他排名,问两种计分方式的冠军各是谁。

分析

大水题,记录每个人获各名次的数量并给每个人编号,暴力排序即可。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
map<string,int>rank[60];
string name[10010];
map<string,bool>used;
int point[20],champ[10010];
int ok,R;
struct node{
      int pl,a;
}rating[10010];
bool cmp(const node &x,const node &y){
      return x.a>y.a;
}
inline void check(int le,int ri,int level,int p){
      if(le==ri){
          if(p)ok=1;
          cout<<name[rating[le].pl]<<endl;
          return;
      }
      if(level==2&&p){
           R=ri;
         return;
      }
      int i,j,k=0;
      for(i=le;i<=ri;i++)
         rating[i].a=rank[level][name[rating[i].pl]];
      sort(rating+le,rating+ri+le,cmp);
      for(i=le;i<=ri;i++)
         if(rating[i+1].a!=rating[i].a){
             check(le,i,level+1,p);
             k=1;
             break;
         }
      if(!k)check(le,ri,level+1,p);
}
int main()
{     int n,m,i,j,k,t,cnt=0;
      cin>>t;
      for(m=1;m<=t;m++){
          cin>>n;
          for(i=1;i<=n;i++){
              string s;
              cin>>s;
              if(!used[s]){
                  used[s]=1;
                  name[++cnt]=s;
              }
              rank[i][s]++;
          }
      }
      point[1]=25,
      point[2]=18,
      point[3]=15,
      point[4]=12,
      point[5]=10,
      point[6]=8,
      point[7]=6,
      point[8]=4,
      point[9]=2,
      point[10]=1;
      for(i=1;i<=cnt;i++)
          for(j=1;j<=10;j++){
             rating[i].a+=rank[j][name[i]]*point[j];
           rating[i].pl=i;
        }
      sort(rating+1,rating+cnt+1,cmp);
      for(i=1;i<=cnt;i++)
         if(rating[i+1].a!=rating[i].a){
             check(1,i,1,0);
             break;
         }
      check(1,cnt,1,1);
      if(ok)return 0;
      for(i=1;i<=cnt;i++)rating[i].a=0;
      for(i=1;i<=R;i++){
          for(j=1;j<=10;j++){
             rating[i].a+=rank[j][name[rating[i].pl]]*point[j];
        }
      }
      sort(rating+1,rating+R+1,cmp);
      for(i=1;i<=R;i++)
         if(rating[i+1].a!=rating[i].a){
             check(1,i,2,0);
             break;
         }
      return 0;
}

24B F1 Champions的更多相关文章

  1. CodeForces 24B F1 Champions(排序)

    B. F1 Champions time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. CF24B F1 Champions 题解

    Content 有 \(n\) 场已经进行完的赛车比赛,每场比赛给出前 \(m\) 名的名字.在每场比赛中,前 \(10\) 名的选手分别可以获得 \(25,18,15,12,10,8,6,4,2,1 ...

  3. Online, Asynchronous Schema Change in F1

    F1: A Distributed SQL Database That Scales   http://disksing.com/understanding-f1-schema-change   ma ...

  4. VB.NET中Form窗体运行时,按F1进入全屏状态

    1.在KeyDown事件中添加: If e.KeyValue = 112 Then Me.WindowState = FormWindowState.Maximized End If 注:1.其中11 ...

  5. SSIS excel2003文件导入列名显示为F1,F2 - FN

    问题现象: 数据源2003版本的EXCEL文件,第一列是空白,数据是从第二列开始的.所以SSIS中用EXCEL数据源倒入这个EXCEL时,所有的列显示不出来,显示的是F1,F2  - FN. 解决方法 ...

  6. Ubuntu 14 常用“快捷键”,Ctrl + Alt + F1 进入终端,按 Ctrl + Alt + F7 回到界面

    Ubuntu中所谓 Super键,就是 Windows建,一般在键盘的 ctrl 和 alt 2个键之间,一个微软窗口的图标. 1.持续按住 Super键,会弹出“键盘快捷键”大全: 2.修改快捷键路 ...

  7. Delphi按下F1不能出现帮助文档的解决方法

    不光是Delphi,Windows里面所有的之所以无法打开.hlp帮助文档的问题都可以使用以下的方法来解决 问题:情况是这样的,不是打不开hlp帮助文档,按F1出现的是Windows的帮助.而Delp ...

  8. F1 分数

    F1 分数会同时考虑精确率和召回率,以便计算新的分数. 可将 F1 分数理解为精确率和召回率的加权平均值,其中 F1 分数的最佳值为 1.最差值为 0: F1 = 2 * (精确率 * 召回率) / ...

  9. SAP大数据为"海上F1"提供技术支持

    “海上F1”的2014极限帆船赛在青岛开赛,这场大赛是技术与体育高度融合的盛会.比赛中,每一个船员将使用各种高新技术,应尽所能,战胜对手.很多人之所以喜欢这样的比赛,是因为帆船比赛是世界上最复杂的一项 ...

随机推荐

  1. ajax的原理及使用

    ajax并非是一门新的技术,而是现有技术的一种新的组合用法,即是结合异步javascript和XML,它是一种创建快速动态网页的技术.其中,异步javascript是相对于同步而言的,同步模式通常称为 ...

  2. 【leetcode刷题笔记】Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  3. INT(M)表示什么意思?

    根据官方文档描述,int(M)中的M表示数据显示的宽度,与实际存储的长度无关. 1.也就是int(3)和int(11)能够存储的数据是一样的,都是从-2147483648到2147483647(或者0 ...

  4. css目录

    想看css文章目录? 点击我

  5. 签offer和签三方协议

    一般来讲,签约分为两种:签offer和签三方协议.其中,前者对个人及企业的约束效力远不及后者.下面分别来介绍. 1.签offer offer一般是单位提供给你的一个录用意向,以合同的形式提供给你,要求 ...

  6. ios9 3dtouch 博客

    http://my.oschina.net/u/2340880/blog/511509#OSC_h3_3

  7. vmware workstation pro 安装ubantu虚拟机

    参考:https://ywnz.com/linuxaz/3904.html https://www.zhihu.com/search?type=content&q=vmware%20works ...

  8. 用 CSS3 创建一个漂亮的多种色彩的菜单

    1. [图片] thumb.png ​2. [代码][HTML]代码 <!DOCTYPE html><html lang="en" >    <hea ...

  9. 在Win8.1系统下如何安装运行SQL Server 2005

    按正常情况,在Win8/Win8.1系统下安装微软的SQL Server 2005套件会存在兼容问题,即使安装完,最后的结果就是导致其服务项无法正常启动. 如果用户创建使用的项目非要按照SQL Ser ...

  10. Sqlte 知识点记录

    1.表存在 select count(*) from sqlite_master where type='table' and name='MyTable'; sql),path ))"; ...