码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 4974 A simple water problem(数学题)

时间:2014-08-21 22:56:45      阅读:481      评论:0      收藏:0      [点我收藏+]

标签:hdu   数学   

题目链接: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


代码如下:

#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

hdu 4974 A simple water problem(数学题)

标签:hdu   数学   

原文地址:http://blog.csdn.net/u012860063/article/details/38736725

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!