codeforces 200c

C - Football Championship
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Any resemblance to any real championship and sport is accidental.

The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship:

  • the team that kicked most balls in the enemy's goal area wins the game;
  • the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points;
  • a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team;
  • the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship.

In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one):

  • the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place;
  • the total number of scored goals in the championship: the team with a higher value gets a higher place;
  • the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place.

The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions:

  • X > Y, that is, Berland is going to win this game;
  • after the game Berland gets the 1st or the 2nd place in the group;
  • if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum;
  • if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum.

Input

The input has five lines.

Each line describes a game as "team1team2goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9.

The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games.

Output

Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes).

Note, that the result score can be very huge, 10:0 for example.

Sample Input

Input
AERLAND DERLAND 2:1
DERLAND CERLAND 0:3
CERLAND AERLAND 0:1
AERLAND BERLAND 2:0
DERLAND BERLAND 4:0
Output
6:0
Input
AERLAND DERLAND 2:2
DERLAND CERLAND 2:3
CERLAND AERLAND 1:3
AERLAND BERLAND 2:1
DERLAND BERLAND 4:1
Output
IMPOSSIBLE


不难但是很麻烦呀。

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
struct A
{
    string name;
    int score;
    int point;
    int miss;
    int time;
    friend bool operator < (const A &a,const A &b)
    {
        if(a.score!=b.score)
            return a.score>b.score;
        if((a.point-a.miss)!=(b.point-b.miss))
            return a.point-a.miss>b.point-b.miss;
        if(a.point!=b.point)
            return a.point>b.point;
        //return a.name<b.name;
        return strcmp(a.name.data(),b.name.data())<0;
    }
} dui[6],temp[6];
int n;
int addteam(string team)
{
    for(int i=0; i<n; i++)
        if(dui[i].name==team)
            return -1;
    dui[n].name=team;
    dui[n].score=dui[n].miss=dui[n].time=dui[n].point=0;
    n++;
    return n-1;
}
int find1(string a)
{
    for(int i=0; i<n; i++)
        if(dui[i].name==a)
            return i;
}
int main()
{
    //freopen("in.txt","r",stdin);
    string team1,team2;
    int score1,score2,t1,t2;
    char x;
    n=0;
    for(int i=0; i<5; i++)
    {
        cin>>team1>>team2>>score1>>x>>score2;
        addteam(team1);
        addteam(team2);
        t1=find1(team1);
        t2=find1(team2);
        if(score1>score2)
            dui[t1].score+=3;
        else if(score1<score2)
            dui[t2].score+=3;
        else
        {
            dui[t1].score++;
            dui[t2].score++;
        }
        dui[t1].miss+=score2;
        dui[t2].miss+=score1;
        dui[t1].point+=score1;
        dui[t2].point+=score2;
        dui[t1].time++;
        dui[t2].time++;
    }
    bool flag=true;
    sort(dui,dui+n);
    string tempname("BERLAND");
    t1=find1(tempname);
    int m;
    if((dui[t1].score+3<dui[1].score)&&(dui[t1].score+3<dui[0].score))
    {
        flag=false;
        cout<<"IMPOSSIBLE"<<endl;
    }
    if(flag)
    {
        flag=false;
        for(int i=0; i<n; i++)
            if(i!=t1)
                if(dui[i].time<3)
                {
                    m=i;
                    break;
                }
        int min1=100000;
        for(int i=0; i<=100; i++)
        {
            for(int j=i+1; j<=100; j++)
            {
                for(int k=0; k<n; k++)
                    temp[k]=dui[k];
                temp[m].miss+=j;
                temp[t1].miss+=i;
                temp[m].point+=i;
                temp[t1].point+=j;
                if(i==j)
                {
                    temp[m].score++;
                    temp[t1].score++;
                }
                else if(i<j)
                    temp[t1].score+=3;
                sort(temp,temp+n);
                int tp;
                for(int l=0; l<n; l++)
                    if(temp[l].name==tempname)
                    {
                        tp=l;
                        break;
                    }

                if(tp<2)
                    if(j-i<min1)
                    {
                        score1=j;
                        score2=i;
                        min1=j-i;
                        flag=true;
                    }
            }
        }
        if(flag)
            printf("%d:%d\n",score1,score2);
        else
            cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值