首页 > 其他 > 详细

hdu1003

时间:2017-01-10 14:29:27      阅读:221      评论:0      收藏:0      [点我收藏+]

//c++
//https://github.com/zzdxfei/hduacm/blob/master/1003.cpp
#include 
#include

using namespace std;

void ComputeMaxSubstr(const vector& sets,
int& max_sum, int& max_left, int& max_right) {
max_sum = sets[0];
max_left = 0;
max_right = 0;
int current_left = 0;
int current_sum = sets[0];
for(int i = 1; i < sets.size(); ++i) {
if(current_sum >= 0) {
current_sum += sets[i];
}
else {
current_left = i;
current_sum = sets[i];
}
if(current_sum > max_sum) {
max_sum = current_sum;
max_left = current_left;
max_right = i;
}
}
}

int main(void) {
int max_sum, left, right;
int num_tests;
int num_nums;
scanf("%d", &num_tests);
for(int i = 0; i != num_tests; ++i) {
scanf("%d", &num_nums);
vector nums(num_nums);
for(int j = 0; j != num_nums; ++j) { scanf("%d", &(nums[j])); }
ComputeMaxSubstr(nums, max_sum, left, right);
printf("Case %d:\n%d %d %d\n", i + 1, max_sum, left + 1, right + 1);
if(i != num_tests - 1) { printf("\n"); }
}
return 0;
}

hdu1003

原文:http://www.cnblogs.com/wangkun1993/p/6268991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!