Hdu4974: A simple water problem

Source: Internet
Author: User
Problem descriptiondragon 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 com Petition 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 privileges t 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?
Inputthe 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.
Outputeach output shoshould occupy one line. each line shoshould 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 shoshould be watched by dragon.
 
Sample Input
132 3 4
 
Sample output
Case #1: 5
#include<cstdio>#include<algorithm>using namespace std;int t,c=1,m,a,i,s,n;main(){    scanf("%d",&t);    while(t--)    {        scanf("%d",&n),s=0,m=0;        while(n--)            scanf("%d",&a),s+=a,m=max(m,a);        printf("Case #%d: %d\n",c++,max(m,(int)(s/2.0+0.5)));    }}


Hdu4974: A simple water problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.