HDU 4974 A simple water problem(贪心)

HDU 4974 A simple water problem

pid=4974" target="_blank" style="">题目链接

签到题,非常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;
}
上一篇:01--css编码技巧--css揭秘


下一篇:java基础知识学习笔记