传送门

题目

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. 20145229吴姗珊 《Java程序设计》第3周学习总结

    20145229吴姗珊 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 4.1类与对象 1.对象(Object):存在的具体实体,具有明确的状态和行为 2.类(Cl ...

  2. UOJ78 二分图最大匹配

    从前一个和谐的班级,有 nlnl 个是男生,有 nrnr 个是女生.编号分别为 1,…,nl1,…,nl 和 1,…,nr1,…,nr. 有若干个这样的条件:第 vv 个男生和第 uu 个女生愿意结为 ...

  3. 各种IoC框架下实现AOP

    .Net AOP(五) 各种IoC框架下实现AOP 利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率 主要功能 日志记录,性 ...

  4. java错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu

    我们在用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not found on t ...

  5. 分享知识-快乐自己:ActiveMQ 安装部署

    1):下载 ActiveMQ tar 包 2):上传到 服务器中 3):解压到 指定目录中 [root@admin tools]# tar -zxvf apache-activemq-5.2.0-bi ...

  6. 理解WCF(第二部分,部分參考他人)

    該篇的主題:wcf到底是怎工作的? 一.什么是分布式: 首先看一张图: 由上图对比我们可以发现,区别就是前者把服务器放在了一台电脑上,而后者把服务器放在了多台电脑上.这样多台电脑处理起来的速度比一台电 ...

  7. Apache配置负载均衡-实例

    公司两台服务器都安装了tomcat,配置apache作为负载均衡,当一台服务器出现故障时还能保证业务正常运行. Server1:192.168.1.100 Server2:192.168.1.200 ...

  8. UI层自动化测试介绍

    UI指的是用户可以用肉眼可以看到的页面. UI层自动化测试的原理.不论是web端还是移动端,原理都是一样的,就是基于页面元素的识别和定位来进行模拟用户行为. 首先识别到某个元素,比如一个按钮,然后定义 ...

  9. Git_错误_03_ Git提交时显示用户 unknown

    这是因为没有设置用户名 $ git config --global user.name "your_name" $ git config --global user.email & ...

  10. L105

    A pill could soon radio signals from inside your gut to help doctors diagnose diseases from ulcers t ...