HDU 4974 A simple water problem 模拟(水

水题。

#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
priority_queue<int> q;
int main() {
    int T, cas = 0;
    scanf("%d", &T);
    while(T-- > 0) {
        int n;
        scanf("%d", &n);
        for(int i = 0, x; i < n; i ++) {
            scanf("%d", &x);
            q.push(x);
        }
        ll ans = 0;
        while(!q.empty()) {
            if(q.size() >= 2) {
                int x = q.top(); q.pop();
                int y = q.top(); q.pop();
//                printf("%d %d\n", x, y);
                ans += y;
                q.push(x-y);
            } else {
                ans += q.top();
                q.pop();
            }
        }
        printf("Case #%d: ", ++cas);
        cout << ans << endl;
    }
    return 0;
}

HDU 4974 A simple water problem 模拟(水

时间: 2024-10-10 05:09:02

HDU 4974 A simple water problem 模拟(水的相关文章

hdu 4974 A simple water problem(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4974 Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or

HDU 4974 A simple water problem(贪心)

HDU 4974 A simple water problem 题目链接 签到题,很容易贪心得到答案是(sum + 1) / 2和ai最大值的最大值 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 100005; typedef long long ll; int t, n; ll a, Max, sum; int main(

HDU - 4974 A simple water problem

Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or 1 for each competitor and add it to the total score

2014多校第十场1004 || HDU 4974 A simple water problem

题目链接 题意 : n支队伍,每场两个队伍表演,有可能两个队伍都得一分,也可能其中一个队伍一分,也可能都是0分,每个队伍将参加的场次得到的分数加起来,给你每个队伍最终得分,让你计算至少表演了几场. 思路 : ans = max(maxx,(sum+1)/2) :其实想想就可以,如果所有得分中最大值没有和的一半大,那就是队伍中一半一半对打,否则的话最大的那个就都包了. 1 #include <cstdio> 2 #include <cstring> 3 #include <st

hdu - 4974 - A simple water problem(贪心 + 反证)

题意:N个队(N <= 100000),每个队有个总分ai(ai <= 1000000),每场比赛比赛双方最多各可获得1分,问最少经过了多少场比赛. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4974 -->>我们应该尽量使每场比赛的得分为1 : 1,这样可以达到最少的比赛场数(不小于单个队伍的分数). 假设有2场比赛的比分为1 : 0, 1)a : b = 1 : 0,c : d = 1 : 0,这时可以安排a : c = 1

HDOJ 4974 A simple water problem

A simple water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 173    Accepted Submission(s): 112 Problem Description Dragon is watching competitions on TV. Every competition is held be

hdu 5170 GTY&#39;s math problem(水,,数学,,)

题意: 给a,b,c,d. 比较a^b和c^d的大小 思路: 比较log(a^b)和log(c^d)的大小 代码: int a,b,c,d; int main(){ while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF){ double x1 = b*log((double)a); double x2 = d*log((double)c); if(fabs(x1-x2)<eps){ puts("=")

hdu 1757 A Simple Math Problem (乘法矩阵)

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2441    Accepted Submission(s): 1415 Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) =

HDU 4978 A simple probability problem

A simple probability problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 43    Accepted Submission(s): 14 Problem Description Equally-spaced parallel lines lie on an infinite plane. The sep