CSU-2007 Football Training Camp

Football Training Camp

在一次足球联合训练中一共有n支队伍相互进行了若干场比赛。 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为平局则两支队伍各得1分。

Input
输入包含不超过1000组数据。 每组数据的第一行为一个整数n(2 ≤ n ≤ 20),第二行为n个整数s1, s2, …, sn(0 ≤ si ≤ 200, 1 ≤ i ≤ n),即各个队伍目前的得分。

Output
对于每组数据,用一行输出最少以及最多进行了多少场比赛,中间用一个空格隔开。 数据保证不会出现无解情况。

Sample Input
2
7 4
3
1 5 1
2
0 0
Sample Output
4 5
3 3
0 0

题解 : 还是太菜呀,想的情况太少了,一开始直觉就是简单贪心,就是最多比赛是全是平局,最少比赛就是最多赢的局,也确实没什么问题,但是细节把握太差,考虑不细致,即有时并不是全打平局,举个数据

3

6 0 0

用优先队列维护,并找到最后一个能构成全是平局的局面,就退出。那什么情况是可以全打平局呢? 最大值*2<=sum&&sum%2==0;

有参考此处代码

#include<stdio.h>
#include<queue>
using namespace std;
priority_queue<int >que;
int a[1001];
const int INF=0x3f3f3f3f;

int main()
{
    int n;
//  freopen("data.txt","r",stdin );
    while(scanf("%d",&n)!=EOF)
    {
        int sum=0,m=0,ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i] );
            que.push(a[i]);
            sum+=a[i];
        }
        int MAX=0,MIN=INF,tot=0;
        while(1)
        {
            int k=que.top();que.pop();
            if(k*2<=sum&&sum%2==0)
            {
                MAX=max(tot+sum/2,MAX);
                MIN=min(tot+sum/2,MIN);
            }
            if(k<3)
                break;
            sum-=3;
            que.push(k-3);
            tot++;
        }
        printf("%d %d\n",MIN,MAX );
        while(!que.empty())
            que.pop();
    }
    return 0;
}

/*
15
175 31 101 0 71 60 45 101 168 55 168 151 25 37 50 
5
30 27 99 195 27 
10
195 179 132 162 147 55 166 42 142 53 
6
147 50 193 161 176 81  
*/

猜你喜欢

转载自blog.csdn.net/qq_39576425/article/details/80100496