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,如需转载请自行联系原作者
相关文章
|
6月前
|
开发框架 .NET
poj 3468 A Simple Problem with Integers线段树区间修改
题目意思很简单,有N个数,Q个操作, Q l r 表示查询从l到r 的和,C l r v 表示将从l到r 的值加上v,明显的线段树,不知道线段树的人肯定暴力,肯定超时,哈哈!!
19 0
|
8月前
UVa11565 - Simple Equations
UVa11565 - Simple Equations
35 0
|
8月前
UVa11714 - Blind Sorting
UVa11714 - Blind Sorting
36 0
|
Unix Python
LeetCode 71. Simplify Path
给定文件的绝对路径(Unix下的路径)字符串,简化此字符串。
62 0
LeetCode 71. Simplify Path
|
人工智能
UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high building.
1159 0
|
Java
HDU 5882 Balanced Game
Balanced Game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 508    Accepted Submission(s): ...
816 0
|
数据挖掘
poj-1207 THE 3n+1 problem
Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.
773 0

热门文章

最新文章