UVALive 7147 World Cup(2014 Regionals 2014 :: Asia - ShangHai)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94610#problem/J
problemIn normal football games, the winner team gets 3 points, loser team gets 0 point, and if there is a drawgame, both of the teams get 1 point.
In normal football games, the winner team gets 3 points, loser team gets 0 point, and if there is a draw
game, both of the teams get 1 point.
In World Cup 1994, Group D there is an interest thing happened. There are 4 teams in that group,
Argentina, Nigeria, Bulgaria and Greece. Greece lost all the 3 matehes and scored 0. Argentina defeated
Nigeria, Nigeria defeated Bulgaria and Bulgaria defeat Argentina. Since there are only 2 teams could
advance to the next stage, one of the 3 teams will be eliminated. It’s really a surprise that a team
scored 6 will be eliminated in a 4 advance 2 group competition. That is really interesting and we’d like
to dig it deeper.
In this problem, there are N teams in a group. Within a group, any two teams will play each other
exactly once, so each team will have N − 1 matches in total.
In a match, the winner team will get A points and the loser team gets C points. If the match ends
with a draw, each of the teams gets B points. When all matches finished, the teams will be ranked by
their score (in case of multiple teams get the same score, they will be ordered randomly), and the top
M teams from the group can advance to the next stage.
Our questions are: What is the maximum possible score that a team can earn and still not advance?
(Note that there may be other teams in the same group that also earn that same score and do advance.)
Similarly, what is the minimum possible score that a team can earn and still advance?
Input
The first line of the input gives the number of test cases, T. T cases follow. Each case has two lines.
The first line contains two numbers, N and M. The second line contains three numbers, A, B, and C.
Output
For each test case, output one line containing ‘Case #x: y z’, where x is the test case number (starting
from 1) and y is maximum score that a team may be eliminated. z is the minimum score that a team
may advance to the next stage.
Limits:
1 ≤ T ≤ 100,
1 ≤ M < N ≤ 109
,
0 ≤ A, B, C ≤ 109
,
Sample Input:
3
4 2
3 1 0
4 2
3 2 0
2 1
2 3 1
Sample Output:
Case #1: 6 2
Case #2: 7 3
Case #3: 3 2
题意:有n个人参加比赛,只有m个人才能晋级,现在知道赢的分数,平局的分数,输的分数,问一个选手不能晋级时可能得到的最多分数,和可以晋级时可能得到的最少的分数。
不能晋级得到的最高分数:尽可能的让第m+1个人和前m个人达到分数相同的状态(共有m场比赛,可以让所有人平局,也可以赢一次输一次,注意奇数时的特判),并且赢了后面所有的人(或者和后面所有人平局);
能晋级得到的最低分数:让第m个人输给前面所有的人(或者和前面所有人平局),尽可能的让他与后面的人得到相同的分数(共有n-m场比赛,可以让所有人平局,也可以赢一次输一次,注意奇数时的特判)。
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<queue> #include<algorithm> using namespace std; const int N=1e5+10; const int M=50000; const int INF=0x3f3f3f3f; int main () { int T, k = 0; long long Min, Max, m, n, a, b, c, x1, y1, x2, y2; ///x计算的是最高不能晋级的,y计算的是最低可以晋级的 scanf("%d", &T); while (T--) { k++; scanf("%lld%lld", &n, &m); scanf("%lld%lld%lld", &a, &b, &c); if (a < c) swap(a, c); ///赢的人得到的分数可能比输的人得到的分数要少 x1 = (n-m-1)*max(a, b); ///计算第m+1个人与后面所有人比赛得到的分数 x2 = m/2 * 2*b; ///计算第m+1个人与前面所有人平局的分数,由于m可能是奇数,当它为奇数时,此时第m场比赛得到的分数还没有算 if (m % 2 == 0) { x2 = max(x2, m/2*(a+c)); ///为偶数,直接比较赢一次输一次和平局的大小 Max = x1 + x2; } else { x2 = max(x2, m/2*(a+c)); ///为奇数,先比较前m-1场比赛中赢一次输一次和平局的大小 Max = x1 + x2 + max(b, c); ///第m场比赛,需要比较输和平局的大小,再赢就可以晋级了 } y1 = (m-1)*min(c, b); y2 = (n-m)/2 * 2*b; if ((n-m) % 2 == 0) { y2 = min(y2, (n-m)/2*(a+c)); Min = y1 + y2; } else { y2 = min(y2, (n-m)/2*(a+c) ); Min = y1 + y2+min(a, b); ///第n-m场比赛,需要比较赢和平局的大小,再输就不能晋级了 } printf("Case #%d: %lld %lld\n", k, Max, Min); } return 0; }