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(判断线段相交)
75 0
|
开发框架 .NET
poj 3468 A Simple Problem with Integers线段树区间修改
题目意思很简单,有N个数,Q个操作, Q l r 表示查询从l到r 的和,C l r v 表示将从l到r 的值加上v,明显的线段树,不知道线段树的人肯定暴力,肯定超时,哈哈!!
34 0
HDOJ 1016 Prime Ring Problem素数环【深搜】
HDOJ 1016 Prime Ring Problem素数环【深搜】
120 0
HDOJ 1016 Prime Ring Problem素数环【深搜】
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
128 0
|
C语言
HDOJ 1016 Prime Ring Problem素数环【深搜2】
HDOJ 1016 Prime Ring Problem素数环【深搜】
99 0
|
Go
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
112 0
LeetCode---Problem6 ZigZag Conversion
ZigZag问题思路。代码整洁并不一定执行速度就好~
794 0
|
人工智能
UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high building.
1188 0