Codeforces Round #126 (Div. 2) C 模拟



链接:戳这里


C. Football Championship
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 "team1 team2 goals1: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.

Examples
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
Note
In the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end:

AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5)
BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6)
DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5)
CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3)
In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage.

题意:

足球比赛四只球队在一个组,每两只球队只打一场比赛,总共6场比赛

排名是积分制的:具体看题目


思路:

模拟就可以了,关键字的排序看代码


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
map<string,int> P;
map<string,int> D;
map<string,int> S;
map<string,int> Name;
struct node{
    int x,y,z;
    string name;
    node(int x=0,int y=0,int z=0,string name=""):x(x),y(y),z(z),name(name){}
    bool operator < (const node &a)const{
        if(x==a.x && y==a.y && z==a.z) return name<a.name;
        else if(x==a.x && y==a.y) return z>a.z;
        else if(x==a.x) return y>a.y;
        return x>a.x;
    }
}a[10];
bool pd(string s,string p,int x,int y){
    if(x>y){
        P[s]+=3;
        P[p]+=0;
        D[s]+=x-y;
        D[p]+=y-x;
        S[s]+=x;
        S[p]+=y;
    }
    int cnt=0;
    for(auto & t : P){
        string tmp=t.first;
        if(tmp=="BERLAND"){
            a[0].x=t.second;
            a[0].y=D[tmp];
            a[0].z=S[tmp];
            a[0].name=tmp;
        } else {
            a[++cnt].x=P[tmp];
            a[cnt].y=D[tmp];
            a[cnt].z=S[tmp];
            a[cnt].name=tmp;
        }
    }
    sort(a,a+cnt+1);
    int f=0;
    if(a[0].name=="BERLAND" || a[1].name=="BERLAND") f=1;
    else f=0;
    if(x>y){
        P[s]-=3;
        P[p]-=0;
        D[s]-=x-y;
        D[p]-=y-x;
        S[s]-=x;
        S[p]-=y;
    }
    if(f) return true;
    return false;
}
string s,p;
int x,y;
int main(){
    for(int i=0;i<5;i++){
        cin>>s>>p;
        scanf("%d:%d",&x,&y);
        Name[s]++;
        Name[p]++;
        if(x>y){
            P[s]+=3;
            P[p]+=0;
            D[s]+=x-y;
            D[p]+=y-x;
            S[s]+=x;
            S[p]+=y;
        } else if(x==y){
            P[s]+=1;
            P[p]+=1;
            D[s]+=x-y;
            D[p]+=y-x;
            S[s]+=x;
            S[p]+=y;
        } else if(x<y){
            P[s]+=0;
            P[p]+=3;
            D[s]+=x-y;
            D[p]+=y-x;
            S[s]+=x;
            S[p]+=y;
        }
    }
    string op;
    for(auto & t : P){
        if(Name[t.first]==2 && t.first!="BERLAND") op=t.first;
    }
    int x,y,f=0,ans=1e9;
    for(int i=0;i<=100;i++){
        for(int j=0;j<i;j++){
            if(pd("BERLAND",op,i,j)){
                f=1;
                if(i-j<ans){
                    ans=i-j;
                    f=1;
                    x=i;
                    y=j;
                }
                else if(i-j==ans){
                    f=1;
                    if(j<y){
                        x=i;
                        y=j;
                    }

                }
            }
        }
    }
    if(f) printf("%d:%d\n",x,y);
    else printf("IMPOSSIBLE\n");
    return 0;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值