HDU 4974 A simple water problem(贪心)

简介:

HDU 4974 A simple water problem

题目链接

签到题,非常easy贪心得到答案是(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() {
    int cas = 0;
    scanf("%d", &t);
    while (t--) {
	scanf("%d", &n);
	Max = 0;
	sum = 0;
	ll num = 0;
	for (int i = 0; i < n; i++) {
	    scanf("%I64d", &num);
	    Max = max(Max, num);
	    sum += num;
	}
	sum = (sum + 1) / 2;
	printf("Case #%d: %I64d\n", ++cas, max(sum, Max));
    }
    return 0;
}





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5139461.html,如需转载请自行联系原作者
相关文章
|
图形学
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
71 0
|
开发框架 .NET
poj 3468 A Simple Problem with Integers线段树区间修改
题目意思很简单,有N个数,Q个操作, Q l r 表示查询从l到r 的和,C l r v 表示将从l到r 的值加上v,明显的线段树,不知道线段树的人肯定暴力,肯定超时,哈哈!!
33 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
52 0
|
Unix Python
LeetCode 71. Simplify Path
给定文件的绝对路径(Unix下的路径)字符串,简化此字符串。
84 0
LeetCode 71. Simplify Path
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
115 0
|
人工智能
UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high building.
1184 0