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 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 (a 1,a 2,a 3,...,a n).a i(<=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 题意:给你n个初值为0的数,每次你可以任选两个做加操作,可以是0或者1,求最少的操作使的这n个数变为题目所给的n个数 思路:贪心,显然我们是尽量两个都做+1操作,那么我们先求出最大的,让他带着+1,然后是前n-1个数的和如果小于的话,最小操作就是最大的数,否则还要进行操作
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> typedef __int64 ll; using namespace std; int main() { int t, n, cas = 1; scanf("%d", &t); while (t--) { scanf("%d", &n); int Max = -1, a; ll sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a); sum += a; if (Max < a) Max = a; } sum -= Max; ll ans; if (Max >= sum) ans = Max; else ans = Max + (sum - Max + 1) / 2; printf("Case #%d: %I64d\n", cas++, ans); } return 0; }
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef __int64 ll;
using namespace std;

int main() {
	int t, n, cas = 1;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		int Max = -1, a;
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a);
			sum += a;
			if (Max < a)
				Max = a;
		}
		sum -= Max;
		ll ans;
		if (Max >= sum)
			ans = Max;
		else ans = Max + (sum - Max + 1) / 2; 
		printf("Case #%d: %I64d\n", cas++, ans);
	}
	return 0;
} 


转载于:https://my.oschina.net/pangzhuzhu/blog/318055

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值