zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        }
        return 0;
    }


  • 相关阅读:
    Go反射
    Go_CSP并发模型
    Go_select
    Go计时器
    day9:vcp考试
    day8:vcp考试
    day7:vcp考试
    day6:vcp考试
    day5:vcp考试
    day4:vcp考试
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4046833.html
Copyright © 2011-2022 走看看