hdu 4974 贪心

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;
}


转载于:https://www.cnblogs.com/zibaohun/p/4046833.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值