标签:des style blog http color io os ar for
事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧!
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
2 5 6 -1 5 4 -7 7 0 6 -1 1 -6 7 -5
Case 1: 14 1 4 Case 2: 7 1 6
代码例如以下:
#include <cstdio>
#define INF 0x3fffffff
#define M 100000+17
int a[M];
int main()
{
	int n, i, T, k = 0;
	while(~scanf("%d",&T))
	{
		while(T--)
		{
			scanf("%d",&n);
			int s = 1, e = 1, t = 1;
			int sum = 0, MAX = -INF;
			for(i = 1; i <= n; i++)
			{
				scanf("%d",&a[i]);
				sum+=a[i];
				if(sum > MAX)
				{
					s = t;
					e = i;
					MAX = sum;
				}
				if(sum < 0)
				{
					t = i+1;
					sum = 0;
				}
			}
			printf("Case %d:\n",++k);
			printf("%d %d %d\n",MAX,s,e);
			if(T!=0)
				printf("\n");
		}
	}
	return 0;
}
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/lcchuguo/p/4001471.html