码迷,mamicode.com
首页 > 其他好文 > 详细

24B F1 Champions

时间:2018-04-19 21:47:15      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:lower   term   namespace   input   ctime   暴力   return   mes   HERE   

传送门

题目

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

标签:lower   term   namespace   input   ctime   暴力   return   mes   HERE   

原文地址:https://www.cnblogs.com/yzxverygood/p/8886237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!