天天看點

Code forces 200C---Football Championship

<a href="http://codeforces.com/problemset/problem/200/C" target="_blank">點選打開連結</a>

題目:

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 &gt; 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 teamteam1 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)

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.

題目意思:   有4支足球隊進行足球比賽,其中有一支是BERLAND,現在這支隊伍要和剩下的隊伍三支隊伍中還少一場比賽的隊伍進行最後一場比賽,已知前面的5場比賽的結果,要求能否找到一個比分X:Y,使得BERLAND赢球,并且X-Y的內插補點最小,如果存在輸出X:Y,否則輸出IMPOSSIBLE.

滿足以下條件:

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.

解題思路:模拟整個過程即可(對名有可能會和樣列不同是以我加了一個處理對名的操作)、

1:将讀入的資料處理存到一個s[4]數組對于四個隊,預設BERLAND為s[3]

2:我們用兩個for去枚舉是以可能的X Y的比值,然後去處理排名,如果最後BERLAND是前兩名即可.

3:當遇到相同分數時候判斷條件為3個優先級從上往下先比較第一個不行比第二個最後看第三個

1:進球數-失球數的內插補點,內插補點小的優先

2:進球數多的優先

3:對名的字典序小的優先

代碼:

繼續閱讀