传送门

题目

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. 转的es6 =>函数

    原文地址 箭头函数=>无疑是ES6中最受关注的一个新特性了,通过它可以简写 function 函数表达式,你也可以在各种提及箭头函数的地方看到这样的观点--"=> 就是一个新的 ...

  2. dbgrid,datasoure,ClientDataSet的简单应用

    dbgrid是用来在界面上显示数据的,需要连接源dbgrid1.datasource := datasource1; datasource:作为dbgrid,clientDataset的连接桥梁,需要 ...

  3. MyCat:开源分布式数据库中间件

    mycat 的主要配置文件 schema.xml rule.xml server.xml 客户端连接mycat mysql -h192.168.1.1 -P8806 -uroot -pwangxiao ...

  4. linux 压缩和归档

    在linux下有几种压缩方式:gzip.bzip2.xz.zip gzip 压缩文件以.gz结尾, 只能压缩文件,不能压缩目录 用法: gzip:/path/to/somefile   用来压缩,完成 ...

  5. Vue2.0总结———vue使用过程常见的一些问题

    Vue目前的的开发模式主要有两种:1.直接页面级的开发,script直接引入Vue2.工程性开发,webpack+loader或者直接使用脚手架工具Vue-cli,里面的文件都配置好了 webpack ...

  6. BEC listen and translation exercise 38

    很高兴看到有这么多人想了解我们的体育设施.It's good to see that there are so many people wanting to find out about our sp ...

  7. python中的enumerate()函数用法

    enumerate函数用于遍历序列中的元素以及它们的下标,可以非常方便的遍历元素. 比如我在往excel中写数据时就用到了这个函数: data = [] data.append(('预约码', '车牌 ...

  8. Java 对象引用以及对象赋值

    一.Vehicle veh1 = new Vehicle(); 通常这条语句执行的动作被称为创建一个对象,其实他包含了四个动作. 1.new Vehicle  :表示在堆空间内创建了一个Vehicle ...

  9. I.MX6 FFmpeg 录制视频

    /************************************************************************* * I.MX6 FFmpeg 录制视频 * 说明: ...

  10. HDU4699:Editor

    浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=46 ...