`
阿尔萨斯
  • 浏览: 4109471 次
社区版块
存档分类
最新评论

hdu 4974 A simple water problem(水题)

 
阅读更多

题目链接:hdu 4974 A simple water problem

题目大意:n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一个人加分,或者都不加。给出最后的比分情况,问说最少要比多少次才能获得现在的得分状态。

解题思路:贪心,即使每次都为两人加分的情况下需要的次数(得分总和除2),注意如果答案小于其中某人的单次得分的话说明答案的次数是不够的,因为自己不可能和自己比。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;

int main () {
    int cas, n;
    scanf("%d", &cas);
    for (int kcas = 1; kcas <= cas; kcas++) {
        ll s = 0, u = 0, x;

        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%I64d", &x);
            s += x;
            u = max(u, x);
        }

        s = (s + 1) / 2;
        printf("Case #%d: %I64d\n", kcas, max(s, u));
    }
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics