hdu4974A simple water problem(贪心)

来源:互联网 发布:上海程序员培训学校 编辑:程序博客网 时间:2024/05/21 17:30

A simple water problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 574    Accepted Submission(s): 322


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
132 3 4
 

Sample Output
Case #1: 5
#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int main(){int T,i,n,j;__int64 a,u,s;scanf("%d",&T);for(i=1;i<=T;i++){u=0;s=0;scanf("%d",&n);for(j=0;j<n;j++){scanf("%I64d",&a);s=s+a;u=max(u,a);//个人最高分}s=(s+1)/2;printf("Case #%d: %I64d\n",i,max(s,u));//如果平均值小于个人最高分,则应是个人最高分。}return 0;} 

题意是:多个人进行两两比赛,有一个裁判给每个选手打分,可以给两个人都是1分;也可以一个1分,一个0分;有人可以两个都不给分。
现在知道每个选手的得分,计算最少进行多少次比赛能达到当前的这个状态。
思路:假设进行n场比赛,则选手得分总和最多是2n,即每个选手每次都的1分,即使每次都为两人加分的情况下需要的次数(得分总和除2),注意如果答案小于其中某人的单次得分的话说明答案的次数是不够的,因为自己不可能和自己比。
0 0
原创粉丝点击