传送门

题目

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. JVM - 堆外内存

    看了不少资料,总结下: 堆外内存 / 直接内存(Direct Memory)JDK1.4中引入的NIO类,基于channel和Buffer的I/O方式,可用Native库直接分配堆外内存,然后利用一个 ...

  2. 【leetcode刷提笔记】Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  3. vim设置tab为4空格

    vim的最基础设置 vim的设置需要编辑~/.vimrc文件,更改已有设置或者在后面添加相应的设置. 设置tab为4字符 # ts: tabstop set ts=4 将tab展开为空格 # expa ...

  4. 【二叉堆】k路归并问题(BSOJ1941)

    Description 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci(x∈N*).给定这些Ai.Bi和Ci,请求出所有函数的所有函数值中最小的m个(如有重复 ...

  5. eDocEngine_3.0.4.273的手动安装

    1.安装FastReport 5: 2.编译Shared3(如对Delphi2007,打开gtSharedD11.groupproj项目文件),将产生的bpl.dcp文件分别拷贝到C:\Users\P ...

  6. BZOJ 1562 [NOI2009]变换序列:二分图匹配

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 题意: 给定n,定义D(x,y) =  min(|x-y|, n-|x-y|),然后 ...

  7. webserver的编写中出现的问题

    在webserver编写过程中,出现过问题.就是标签<input>编写过程中少了name属性,导致程序无法读到<form>提交的数据.

  8. iis常见问题解决

    iis7以上版本部署4.0框架项目常见问题解决 配置错误: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的 (overrideModeDefault=&quo ...

  9. php 数组分页

    $p = max(1, I('param.p',1,'intval')); $count = count($date); $Page = new Page($count,15); $Page-> ...

  10. UVA 291 The House Of Santa Claus(DFS算法)

    题意:从 节点1出发,一笔画出 圣诞老人的家(所谓一笔画,就是遍访所有边且每条边仅访问一次). 思路:深度优先搜索(DFS算法) #include<iostream> #include&l ...