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,如需转载请自行联系原作者