【UVA 7147】World Cup

传送门

题目描述

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?

题目翻译

假设有n支球队每两只都会进行一场比赛,赢得分A,平得分B,输得分C,最后按照分数进行排序,选入m个球队晋级。那么,请问无法晋级的最高分为多少? 可以晋级的最低分为多少?

解题思路

首先,我们来考虑第一问,即无法晋级的最高分:

(首先,我们保证赢得分比输高,否则swap一下)

无法晋级的最高分,就是第m+1名的最高分。

那么,在m+1后的所有队伍,就是来送人头的,怎么解释呢? 显然,想让前面的尽可能得分高,就需要m+2及以后的队伍和前面的m+1队比赛是都输,这样,就解决完这两部分之间的比赛了,至于后面的队伍内部的输赢,我们才不管呢 n(*≧▽≦*)n

现在,我们还需要解决前m+1支队伍内部的比赛。这时候,我们就需要分类讨论了:

(1)m是偶数:这时,前m+1支队伍,每一支都进行偶数场,那么,m+1尽可能大的话,又不能超过前面的队伍时,就可以这样玩——一半的比赛赢,一半的比赛输,或者全部平局,这要用A+C和2×B的大小判定。

(2)m是奇数:我们假设每个队伍仍然是比赛偶数场,那么,最终比完时,每个队伍还要再比一场,那么,这个时候,我们的第m+1支对就不能再赢了,因为你如果赢了就排到前面去了,所以,m+1应该在平和输之间选一个更高的。

那么,我们再来考虑第二问,即可以晋级的最低分:

如果第m支队伍想要晋级且分数最低,那么,它需要在和前m-1支队伍比赛的时候,取输和平的最小分。这时,我们还要保证它的得分比后面的队伍得分高,我们还需要分类讨论:

(1)N-M 是一个偶数时:这时很好办,它和后面所有的队伍得分一样即可,求A+C和B×2的最小值。

(2)N-M 是一个奇数时:同第一问的方法,先比偶数场,还剩一场,在赢和平之间挑一场就可以了。

ps:不用long long会溢出!! (╯' - ')╯︵ ┻━┻

代码

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cstdio>
 5 using namespace std;
 6 long long T;
 7 inline void read(long long &x){
 8     x=0; register char ch=getchar();
 9     while(ch<'0'||ch>'9')ch=getchar();
10     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
11 }
12 int main(){
13     read(T);
14     for(register long long t=1;t<=T;t++){
15         long long A,B,C,M,N,ma=0,mi=0,tmp;
16         read(N),read(M);
17         read(A),read(B),read(C);
18         if(C>A)swap(C,A);
19         if(A<=B)ma=(N-1)*B;
20         else {
21             ma+=(N-M-1)*A;
22             if(M%2==0){
23                 tmp=max(B*2,A+C);
24                 ma+=(M/2)*tmp;    
25             }
26             else {
27                 tmp=max(B*2,A+C);
28                 ma+=(M/2)*tmp;
29                 ma+=max(B,C);
30             }
31         }
32         mi+=min(B,C)*(M-1);
33         if((N-M)%2==0){ 
34             tmp=min(A+C,B*2);
35             mi+=tmp*(N-M)/2;
36         }
37         else {
38             tmp=min(A+C,B*2);
39             mi+=tmp*((N-M)/2);
40             mi+=min(A,B);
41         }
42         printf("Case #%lld: %lld %lld\n",t,ma,mi);
43     }
44 }

猜你喜欢

转载自www.cnblogs.com/Fang-Hao/p/9090541.html
CUP