hdu max sum
生活随笔
收集整理的這篇文章主要介紹了
hdu max sum
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這題跟求最大連續(xù)數(shù)列一樣的,稍微不同的是只要把值改為標(biāo)號(hào)就可以了。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<debug.h>
#define X 100001
int A[X];
int main( )
{
int N,M,a,b,c,d,e,f,x,i,y,sum,len=0;
Debug();
scanf("%d",&N);
while(N--)
{
len++;
memset(A,0,sizeof(A));
scanf("%d",&M);
for(i=0;i<M;i++)
scanf("%d",&A[i]);
f=sum=a=b=A[0];
c=d=x=y=1;
for(i=1;i<M;i++)
{
if(sum>=0)
sum+=A[i],c=i+1;
else
sum=A[i],d=c=i+1;
if(sum>f)
{
f=sum;
y=c;
x=d;
}
}
printf("case %d:\n%d %d %d\n",len,f,x,y);
printf(N?"\n":"");
}
//system("pause");
return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/tangcong/archive/2011/04/19/2021459.html
總結(jié)
以上是生活随笔為你收集整理的hdu max sum的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 天文摄影的后期处理
- 下一篇: KALI 2020 软件集成清单——逆向