自爆魂

博客园 首页 新随笔 联系 订阅 管理

http://acm.hdu.edu.cn/showproblem.php?pid=4974

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

直接贪心模拟,或者推出结论为(sum + 1) / 2和ai最大值的最大值

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int n;
int s[100005];

int main() {
    int n,_;
    RD(_);
    for(int cas = 1;cas <= _;++cas){
        printf("Case #%d: ",cas);
        RD(n);
        for(int i = 0;i < n;i++){
            RD(s[i]);
        }
        LL ans = 0,cnt = 0;
        sort(s,s+n);
        for(int j = n-1;j>=0;--j){
            if (cnt >= s[j])
                cnt -= s[j];
            else{
                cnt = s[j] - cnt;
                ans += cnt;
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


posted on 2014-10-21 11:00  自爆魂  阅读(150)  评论(0编辑  收藏  举报