CF24B 模拟

http://codeforces.com/problemset/problem/24/B

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

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 nlines 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.

Sample test(s)
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.

今天还是废在了读题上。。。

/**
CF24B 模拟
题目大意:给出t场比赛的名次,前十名有加分,按照两种不同的排名方式确定排名。
          1、加分最多的为先,若有重复比赛名次靠前的次数越多越靠前,
          2、名次第一的为先,若有相同加分最多优之,若再有重复比赛名次靠前的次数越多越靠前
解题思路:利用结构体,sort一次就行了,只不过处理排序函数时是要小心一点。
*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
using namespace std;
int p[12]= {0,25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct note
{
    string s;
    int point;
    int rank[55];
};

bool cmp1(note a,note b)
{
    if (a.point!=b.point)
        return a.point>b.point;
    for (int i=1; i<=50; i++)
        if (a.rank[i]!=b.rank[i])
            return a.rank[i]>b.rank[i];
}
bool cmp2(note a,note b)
{
    if (a.rank[1]!=b.rank[1])
        return a.rank[1]>b.rank[1];
    if (a.point!=b.point)
        return a.point>b.point;
    for (int i=2; i<=50; i++)
        if (a.rank[i]!=b.rank[i])
            return a.rank[i]>b.rank[i];
}

int main()
{
    int T,n,k;
    while(~scanf("%d",&T))
    {
        note a[205];
        k=0;
        while(T--)
        {
            scanf("%d",&n);
            for(int i=1; i<=n; i++)
            {
                string s;
                cin >> s;
                int flag=1;
                for(int j=0; j<k; j++)
                {
                    if(a[j].s==s)
                    {
                        if(i<=10)
                           a[j].point+=p[i];
                        a[j].rank[i]++;
                        flag=0;
                        break;
                    }
                }
                if(flag)
                {
                    a[k].s=s;
                    if(i<=10)
                        a[k].point=p[i];
                    a[k++].rank[i]=1;
                    flag=0;
                }
            }
        }
      /*  for(int i=0;i<k;i++)
            cout << a[i].s<<" "<<a[i].point<<endl;*/
        sort(a,a+k,cmp1);
        cout << a[0].s<<endl;
        sort(a,a+k,cmp2);
        cout << a[0].s<<endl;
    }
    return 0;
}
MAP的写法

#include <stdio.h>
#include <iostream>
#include <map>
#include <string>
using namespace std;
struct node
{
    int s,p[60];
};
map <string,node> MAP;
bool better1(node &n,node &m)
{
    if (n.s!=m.s)
        return n.s>m.s;
    for (int i=1; i<=50; i++)
        if (n.p[i]!=m.p[i])
            return n.p[i]>m.p[i];
}
bool better2(node &n,node &m)
{
    if (n.p[1]!=m.p[1])
        return n.p[1]>m.p[1];
    return better1(n,m);
}
int main( )
{
    int m,n,l[11]= {0,25,18,15,12,10,8,6,4,2,1};
    string w,x,y;
    cin>>m;
    for (int k=1; k<=m; k++)
    {
        cin>>n;
        for (int i=1; i<=n; i++)
        {
            cin>>w;
            if (i<=10) MAP[w].s+=l[i];
            MAP[w].p[i]++;
        }
    }
    x=y=MAP.begin()->first;
    for (map<string,node>::iterator i=MAP.begin(); i!=MAP.end(); i++)
    {
        if (better1(i->second,MAP[x])) x=i->first;
        if (better2(i->second,MAP[y])) y=i->first;
    }
    cout<<x<<endl<<y<<endl;
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值