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 1 for each competitor and add it to the total score of that competitor. The total
score begins with zero. Here‘s an example: four competitors with name James, Victoria, Penghu, and Digo. First goes a competition between Penghu and Digo, and Dragon enjoys the competition and draw both 1 score for them. Then there’s a competition between
James and Victoria, but this time Dragon draw 1 for Victoria and 0 for James. Lastly a competition between James and Digo is held, but this time Dragon really dislike the competition and give zeroes for each of them. Finally we know the score for each one:
James--0, Victoria--1, Penghu--1, Digo--1. All except James are the Winner!

However, Dragon‘s mom comes back home again and close the TV, driving Dragon to his homework, and find out the paper with scores of all competitors. Dragon‘s mom wants to know how many competition Dragon watched, but it‘s hard through the paper. Here comes
the problem for you, given the scores of all competitors, at least how many competitions had Dragon watched?

Input

The first line of input contains only one integer T(<=10), the number of test cases. Following T blocks, each block describe one test case.

For each test case, the first line contains only one integers N(<=100000), which means the number of competitors. Then a line contains N integers (a1,a2,a3,...,an).ai(<=1000000) means the score of i-th
competitor.

Output

Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. Then for each case just puts a line with one integer, implying the competition at least should be watched by dragon.

Sample Input

1
3
2 3 4

Sample Output

Case #1: 5

Source

2014 Multi-University Training Contest 10

代码如下:

#include <cstdio>
int a[100017];
int main()
{
    int n, t;
    int cas = 0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int sum = 0, maxx = -1;
        for(int i = 0; i < n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
            if(maxx < a[i])
                maxx=a[i];
        }
        if(sum-maxx < maxx)
        {
            printf("Case #%d: %d\n",++cas,maxx);
        }
        else
        {
            printf("Case #%d: %d\n",++cas,(sum+1)/2);
        }
    }
    return 0;
}

hdu 4974 A simple water problem(数学题),布布扣,bubuko.com

时间: 2024-07-30 13:48:00

hdu 4974 A simple water problem(数学题)的相关文章

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 模拟(水

水题. #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) {

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 5974 A Simple Math Problem 数学题

http://acm.hdu.edu.cn/showproblem.php?pid=5974 遇到数学题真的跪.. 题目要求 X + Y = a lcm(X, Y) = b 设c = gcd(x, y); 那么可以表达出x和y了,就是x = i * c; y = j * c; 其中i和j是互质的. 所以lcm(x, y) = i * j * c = b 那么就得到两个方程了. i * c + j * c = a; i * j * c = b; 但是有一个c,三个未知数. 因为i和j互质,所以(i

hdu 5974 A Simple Math Problem(数学题)

Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least Common Multiple (X, Y) =b Input Input includes multiple sets of test data.Each test data occupies one line,including two positive intege

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) =