地址链接:
CF: http://codeforces.com/problemset/problem/200/C
HUSTVirtual Judge:http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=28923
题目:
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 scoreX:Y(whereXis
the number of goals Berland scored andYis 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 scoreX:Y,
where valueX - Yis minimum;
-
if it is still impossible to come up with one score, you should choose the score where valueY(the number of goals Berland misses) is minimum.
Output
Print the required score in the last game asX:Y,
whereXis the number of goals Berland scored andYis
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.
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.
题目大意:
BERLAND参加一个比赛, 总共有4个队伍,6场比赛,一个队伍都要和其他队伍都有比赛,即每队都要打3场比赛。 排名规则详见题目。
给出了前5场的比赛结果。然后要你求最后一场的比赛的比分,这个比分必须让最后这场比赛胜利,而且让最后BERLAND队总排名在第一或者第二。而且这个比分X:Y,
要使得X-Y值最小,如果有几个相同的最小的,那么取其中Y最小的一个。
分析与总结:
题目较繁琐,理解好以后也不难做,主要就是排序。
被这题坑到的地方:Note,
that the result score can be very huge, 10:0 for example. 也就是说最后一场的比分和之前的都不一样, 没有限制最大是9, 可能是非常大。
经测试, 最大取100就可以AC。
代码:
/*
* CodeForces - 200C: Football Championship
* Time: 30 MS
* Result: Accepted
* Author: D_Double
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAXN 100
using namespace std;
struct Team{
char name[30]; // 队名
int point; // 分数
int score; // 赢球个数
int miss; // 输球个数
int time; // 比赛场次
friend bool operator < (const Team&a, const Team&b){
if(a.point!=b.point) return a.point>b.point;
if(a.score-a.miss!=b.score-b.miss) return a.score-a.miss > b.score-b.miss;
if(a.score!=b.score) return a.score>b.score;
return strcmp(a.name, b.name)<0;
}
}arr[5], tmp[5];
int nTeam;
int addTeam(char *str){
for(int i=0; i<nTeam; ++i)
if(strcmp(arr[i].name, str)==0) {
return -1;
}
strcpy(arr[nTeam].name, str);
arr[nTeam].point=arr[nTeam].score=arr[nTeam].miss=arr[nTeam].time = 0;
nTeam++;
return nTeam-1;
}
int findTeam(char *str){
for(int i=0; i<nTeam; ++i)
if(strcmp(arr[i].name, str)==0) return i;
}
int main(){
freopen("input.txt","r",stdin);
char team1[30], team2[30];
int score1, score2;
nTeam = 0;
for(int i=0; i<5; ++i){
scanf("%s %s %d:%d",team1,team2,&score1,&score2);
addTeam(team1); addTeam(team2);
int t1 = findTeam(team1), t2 = findTeam(team2);
arr[t1].time++, arr[t2].time++;
if(score1>score2){ arr[t1].point += 3; }
else if(score2>score1){ arr[t2].point += 3; }
else if(score1==score2) { arr[t1].point++; arr[t2].point++; }
arr[t1].score += score1, arr[t2].score += score2;
arr[t1].miss += score2, arr[t2].miss += score1;
}
char name[30];
strcpy(name, "BERLAND");
sort(arr, arr+nTeam);
bool flag=true;
int t=findTeam(name), opp;
if(arr[t].point+3<arr[0].point && arr[t].point+3<arr[1].point){
flag=false;
printf("IMPOSSIBLE\n");
}
if(flag){
flag=false;
// 找到最后一次要和哪个队打
for(int i=0; i<nTeam; ++i)if(i!=t){
if(arr[i].time < 3){ opp=i; break;}
}
int min=10000;
for(int i=0; i<=MAXN; ++i){ // 对手分数
for(int j=i+1; j<=MAXN; ++j){ // BERLAND队分数
for(int k=0; k<nTeam; ++k){
tmp[k].miss = arr[k].miss;
strcpy(tmp[k].name, arr[k].name);
tmp[k].point = arr[k].point;
tmp[k].score = arr[k].score;
tmp[k].time = arr[k].time;
}
tmp[opp].score+=i; tmp[opp].miss += j;
tmp[t].score += j; tmp[t].miss+=i;
if(i==j) { tmp[t].point++; tmp[opp].point++; }
else if(i<j) tmp[t].point+=3;
sort(tmp, tmp+nTeam);
int temp;
for(int l=0; l<nTeam; ++l)
if(strcmp(tmp[l].name, name)==0) {
temp=l;break;
}
if(temp<2){
if(j-i<min){
flag=true; score1=j; score2=i;
min = j-i;
}
}
}
}
if(flag){
printf("%d:%d\n", score1, score2);
}
else printf("IMPOSSIBLE\n");
}
return 0;
}
—— 生命的意义,在于赋予它意义。
分享到:
相关推荐
codeforces-go :thought_balloon: :light_bulb: :balloon:算法我已经在实现了一些算法。如何练习从难度等于(“您的等级” + 200)的问题开始,您将要解决对您来说非常困难的问题。 花费不超过10分钟,然后再查看...
codeforces-cli 在python和bash中使用简单的解析和检查实现,以解决Codeforce中的竞赛。\ 安装 git clone " https://github.com/siddharth17196/codeforces-cli.git " cd codeforces-cli/scripts bash install.sh ...
codeforces-scraper:刮除来自codeforces的解决方案
GFG-CodeChef-CodeForces-Sol::high_voltage:这是我对GFG,CodeChef和CodeForces的解决方案
codeforces-js Codeforces JS
codeforces-mn:浏览器扩展。 CodeForces.comсайтынбодлогуудыгМонголорчуулгатайгаарүзэх
codeforces-navi Tampermonkey Codeforces主题扩展 你好! 我为Codeforces制作了一个绿色导航的深色主题,默认情况下,在夜晚这是一场噩梦般的夜晚,解决了问题。 安装: 安装。 安装。 捐款开放:)
注销Codeforces-爬虫 这是一个基于 Django 的网站,它使用 Beautiful Soup 从 Codeforces 网站上抓取信息。 它使用 PostgreSQL 作为后端数据库。 以下是该项目的主要特点: 用户注册、登录和注销。 获取即将举行的...
codeforces-cli 用Shell脚本编写的codeforce cli,用于解析比赛的输入,输出和自动测试
codeforces-plugin-sublime-text 注意:仅适用于 C++ 代码。 它能做什么? 编译你的 C++ 代码,构建它,获取测试用例,在上面运行你的代码,比较输出。 它不做什么: 通过互联网神奇地识别您的问题并进行判断。 ...
codeforces-cpp 该存储库包含针对Codeforce编程问题的解决方案
codeforces-crawler 一个建议问题,进行虚拟竞赛并为编码平台codeforce的用户显示用户统计信息的网站。 网站链接: 要求 安装要求 导航到目录并运行 点安装-r requirements.txt 运行项目 导航到目录并运行 python ...
Codeforces-余数 轻量级 Chrome 扩展程序,单击按钮即可显示即将举行的 Codeforces 常规比赛。 要使用扩展名,请将所有文件放入一个目录中。 然后,在 chrome://extensions(开发者模式)中加载解压后的扩展目录。 ...
codeforces-stats-analyzer 可以分析用户个人资料
git clone " https://github.com/ahmmedabir9/codeforces-contest-template.git "cd codeforces-contest-templatenpm install # install the dependencies from package.json用法 export CF_CONTEST=...
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
PDF-CodeForces问题 PDF文件中的CodeForces问题 利用CodeForces提取在这个库中的文件 ,文件夹名代表来自CodeForces网址contests`的ID,每个文件夹包含比赛的问题。 有关CodeForces竞赛的疯狂事实 CodeForces上有937...
Codeforces-Stalker 该项目分析了一个用户的codeforce配置文件,比较了两个用户配置文件,并通过列出所有用户未尝试的竞赛列表来选择任意数量的用户的虚拟竞赛。特征单用户分析用户使用的语言用户裁决用户解决的不同...
leetcode卡Codeforces 统计 一个工具可以帮助您显示 CF 统计信息。 灵感来自 . 范围 范围 默认 必需的 处理 空值 真的 贡献 错误的 错误的 朋友们 错误的 错误的 主题 默认 错误的 主题选择:默认、黑暗 例子 默认 ...
codeforces解决方案 作者: : 链接到我的个人资料: : 我的不和谐:Hue#4607 我的电子邮件: 我针对问题集的解决方案。 新文件将定期显示。 您不应该提交我的文件作为解决方案。使用它们来分析或与其他解决方案...