CodeForces 200C Football Championship(暴力枚举)

C. Football Championship

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 "teamteamgoals1: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 test(s)

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:

  1. AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5)
  2. BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6)
  3. DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5)
  4. 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场,排名前2名的队伍晋级。告诉你前5场的比赛结果,输出在最后一场比赛中BERLAND队如果想晋级的最低的符合要求的比分。

队伍排名和正式足球比赛排名方式相似:先按总得分排名,若总得分相同则按净胜球数排名,若净胜球数相同则按进球数排名,若进球数相同则按队名字典序排名(╯‵□′)╯︵┻━┻。                                                                                
                                         对于最低的符合要求的比分,题目是这样描述的:在获胜的前提下使净胜球数最小,即X:Y中的X-Y最小,若由多种情况满足条件则选择Y最小的情况。

解题思路:

每场每队的进球数在0-9之间,那么暴力枚举即可。关键的是枚举的顺序。首先我们要保证B队获胜,那么X-Y一定大于0,所以我们可以枚举B队净胜球数(即X-Y),再枚举B队失球数(即Y),每次枚举后排序,若B队在前2名则更新答案,这样两层循环之后就可以得出使得(X-Y)最小,同时Y最小的答案。

另外:除了B队外的3支队伍的队名是没有规律的,不要被样例迷惑。

参考代码:

#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const double eps=1e-10;
const int INF=0x3f3f3f3f;
const int MAXN=2100;
struct team
{
    string name;
    int cnt,point,get,lost;
};

bool cmp(const team& a,const team& b)//按照题目的描述进行排序
{
    if(a.point!=b.point)
        return a.point>b.point;
    if((a.get-a.lost)!=(b.get-b.lost))
        return (a.get-a.lost)>(b.get-b.lost);
    if(a.get!=b.get)
        return a.get>b.get;
    return a.name<b.name;
}

map<string,int>m;
team t[5];

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
    char t1[200],t2[200],temp;
    int a,b;
    while(cin>>t1>>t2>>a>>temp>>b)
    {
        m.clear();
        int flag=2;
        m[t1]=1;
        m[t2]=2;
        int cnt=4;
        t[1].name=t1;
        t[2].name=t2;
        t[m[t1]].get=t[m[t2]].lost=a;
        t[m[t1]].lost=t[m[t2]].get=b;
        t[m[t1]].cnt++;
        t[m[t2]].cnt++;
        if(a>b)
        {
            t[m[t1]].point+=3;
            t[m[t2]].point+=0;
        }
        else if(a==b)
        {
            t[m[t1]].point+=1;
            t[m[t2]].point+=1;
        }
        else
        {
            t[m[t1]].point+=0;
            t[m[t2]].point+=3;
        }
        while(cnt--)
        {
            cin>>t1>>t2>>a>>temp>>b;
            if(m[t1]==0)
                m[t1]=++flag;
            if(m[t2]==0)
                m[t2]=++flag;
            t[m[t1]].name=t1;
            t[m[t2]].name=t2;
            t[m[t1]].get+=a;
            t[m[t2]].lost+=a;
            t[m[t1]].lost+=b;
            t[m[t2]].get+=b;
            t[m[t1]].cnt++;
            t[m[t2]].cnt++;
            if(a>b)
            {
                t[m[t1]].point+=3;
                t[m[t2]].point+=0;
            }
            else if(a==b)
            {
                t[m[t1]].point+=1;
                t[m[t2]].point+=1;
            }
            else
            {
                t[m[t1]].point+=0;
                t[m[t2]].point+=3;
            }
        }
        int opponent,me;
        for(int i=1; i<=4; i++)
            if(t[i].name!="BERLAND"&&t[i].cnt==2)
                opponent=i;
            else if(t[i].name=="BERLAND")
                me=i;
        int ans1=INF,ans2=INF;
        for(int dis=50; dis>=1; dis--)//枚举(X-Y)
        {
            for(int los=50; los>=0; los--)//枚举Y
            {
                int ge=los+dis;
                team a[5];
                a[1]=t[1];
                a[2]=t[2];
                a[3]=t[3];
                a[4]=t[4];
                a[me].get+=ge;
                a[opponent].lost+=ge;
                a[me].lost+=los;
                a[opponent].get+=los;
                if(ge>los)
                {
                    a[me].point+=3;
                    a[opponent].point+=0;
                }
                else if(ge==los)
                {
                    a[me].point+=1;
                    a[opponent].point+=1;
                }
                else
                {
                    a[me].point+=0;
                    a[opponent].point+=3;
                }
                sort(a+1,a+4+1,cmp);
                if(a[1].name=="BERLAND"||a[2].name=="BERLAND")
                {
                    ans1=ge;
                    ans2=los;
                }
            }
        }
        if(ans1==INF||ans2==INF)
            printf("IMPOSSIBLE\n");
        else
            printf("%d:%d\n",ans1,ans2);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-15 02:30:11

CodeForces 200C Football Championship(暴力枚举)的相关文章

CodeForces 496D Tennis Game (暴力枚举)

题意:进行若干场比赛,每次比赛两人对决,赢的人得到1分,输的人不得分,先得到t分的人获胜,开始下场比赛,某个人率先赢下s场比赛时, 游戏结束.现在给出n次对决的记录,问可能的s和t有多少种,并按s递增的方式输出. 析:如果枚举s 和 t,那么一定会超时的,所以我们考虑是不是可以不用全枚举.我们只要枚举 t ,然后每次都去计算 s. 首先我们先预处理两个人的获得第 i 分时是第几场比赛.然后每次枚举每个 t,每次我们都是加上t,所以总的时间复杂度为 n*logn. 完全可以接受,注意有几个坑,首先

codeforces Restore Cube(暴力枚举)

1 /* 2 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 3 问是否可以还原出一个立方体的坐标,注意这一句话: 4 The numbers in the i-th output line must be a permutation of the numbers in i-th input line! 5 6 思路: 7 我们只要对输入的每一行数据进行枚举每一个排列, 然后检查时候能构成立方体就好了! 8 检查立方体:找到最小的边长的长度 l, 统计边长为l,

Codeforces 425A Sereja and Swaps(暴力枚举)

题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内,然后找区间外假设有更大的值就替换掉. 求出每一个区间的最大值,最后记录下全部区间的最大值 代码: By lab104_yifan, contest: Codeforces Round #243 (Div. 2), problem: (C) Sereja and Swaps, Accepted, #

Codeforces Round #253 (Div. 2)B(暴力枚举)

就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include<set> #include<vector> #include<

Codeforces Round #266 (Div. 2)B(暴力枚举)

很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找出a和b中最小的那个,然后开始枚举,一直枚举到sqrt(6*n)的向上取整.这样所有可能是答案的情况都有啦.再干别的都是重复的或者肯定不是最小面积的. #include<iostream> #include<cstdio> #include<cstdlib> #includ

CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <c

Coderforces 633D:Fibonacci-ish(map+暴力枚举)

http://codeforces.com/problemset/problem/633/D D. Fibonacci-ish Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f0 and f1 are arbi

Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]

题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5930 题意: 现有四支队伍两两打比赛,总共就是打六场比赛,每场比赛赢的队伍可得 $3$ 分,输的队伍得 $0$ 分,平局则两个队各得 $1$ 分. 现在给出四个队伍最终的积分

hdu5616 暴力枚举

2017-08-25 20:08:54 writer:pprp 题目简述: ? HDU 5616? n个砝码,可以放在天平左右两侧或不放? m次询问,每次询问是否可以测出给定重量? 1 ≤ n ≤ 20? 1 ≤ m ≤ 100 这道题采用枚举的思路的话实现起来还是有点困难的, 要实现的功能是对每个砝码进行处理,加到左边, 加到右边,或者是不加 看了大神的代码,感觉很巧妙, 设置了两个标记数组 vis1[2005], vis2[2005] 一个vis1用来记录当前已经可以实现的重量 另一个vis