hdu 1003请问哪里错了?一直wrong answer
#include<stdio.h>intmain(){intT;longN,k,i,maxfrom[100000],maxsum,a[100000],first,end;...
#include<stdio.h>
int main()
{
int T;
long N,k,i,maxfrom[100000],maxsum,a[100000],first,end;
while(scanf("%d",&T)==1)
{
k=1;
for(;k<=T;k++)
{
scanf("%ld",&N);
for(i=0;i<N;i++)
scanf("%ld",&a[i]);
maxfrom[N-1]=a[N-1];
maxsum=a[N-1];
first=end=N-1;
for(i=N-2;i>=0;i--)
{
if(a[i]>=a[i]+maxfrom[i+1])
{
maxfrom[i]=a[i];
if(a[i]>=maxsum)
{
maxsum=a[i];
first=i;
end=i;
}
}
else
{
maxfrom[i]=a[i]+maxfrom[i+1];
if(maxfrom[i]>=maxsum)
{
maxsum=maxfrom[i];
first=i;
}
}
}
printf("Case %ld:\n",k);
if(k<T)
printf("%ld %ld %ld\n\n",maxsum,first+1,end+1);
else
printf("%ld %ld %ld\n",maxsum,first+1,end+1);
}
}
return 0;
} 展开
int main()
{
int T;
long N,k,i,maxfrom[100000],maxsum,a[100000],first,end;
while(scanf("%d",&T)==1)
{
k=1;
for(;k<=T;k++)
{
scanf("%ld",&N);
for(i=0;i<N;i++)
scanf("%ld",&a[i]);
maxfrom[N-1]=a[N-1];
maxsum=a[N-1];
first=end=N-1;
for(i=N-2;i>=0;i--)
{
if(a[i]>=a[i]+maxfrom[i+1])
{
maxfrom[i]=a[i];
if(a[i]>=maxsum)
{
maxsum=a[i];
first=i;
end=i;
}
}
else
{
maxfrom[i]=a[i]+maxfrom[i+1];
if(maxfrom[i]>=maxsum)
{
maxsum=maxfrom[i];
first=i;
}
}
}
printf("Case %ld:\n",k);
if(k<T)
printf("%ld %ld %ld\n\n",maxsum,first+1,end+1);
else
printf("%ld %ld %ld\n",maxsum,first+1,end+1);
}
}
return 0;
} 展开
2个回答
展开全部
你的程序不能通过这个case
1
4 6 5 -10 10
#include<stdio.h>
int main()
{
int T;
long N,k,i,maxfrom[100000],maxsum,a[100000],first,end,end2;
while(scanf("%d",&T)==1)
{
k=1;
for(;k<=T;k++)
{
scanf("%ld",&N);
for(i=0;i<N;i++)
scanf("%ld",&a[i]);
maxfrom[N-1]=a[N-1];
maxsum=a[N-1];
first=end=end2=N-1;
for(i=N-2;i>=0;i--)
{
if(a[i]>=a[i]+maxfrom[i+1])
{
maxfrom[i]=a[i];
end2=i;
if(a[i]>=maxsum)
{
maxsum=a[i];
first=i;
end=i;
}
}
else
{
maxfrom[i]=a[i]+maxfrom[i+1];
if(maxfrom[i]>=maxsum)
{
maxsum=maxfrom[i];
first=i;
end=end2;
}
}
}
printf("Case %ld:\n",k);
if(k<T)
printf("%ld %ld %ld\n\n",maxsum,first+1,end+1);
else
printf("%ld %ld %ld\n",maxsum,first+1,end+1);
}
}
return 0;
}
1
4 6 5 -10 10
#include<stdio.h>
int main()
{
int T;
long N,k,i,maxfrom[100000],maxsum,a[100000],first,end,end2;
while(scanf("%d",&T)==1)
{
k=1;
for(;k<=T;k++)
{
scanf("%ld",&N);
for(i=0;i<N;i++)
scanf("%ld",&a[i]);
maxfrom[N-1]=a[N-1];
maxsum=a[N-1];
first=end=end2=N-1;
for(i=N-2;i>=0;i--)
{
if(a[i]>=a[i]+maxfrom[i+1])
{
maxfrom[i]=a[i];
end2=i;
if(a[i]>=maxsum)
{
maxsum=a[i];
first=i;
end=i;
}
}
else
{
maxfrom[i]=a[i]+maxfrom[i+1];
if(maxfrom[i]>=maxsum)
{
maxsum=maxfrom[i];
first=i;
end=end2;
}
}
}
printf("Case %ld:\n",k);
if(k<T)
printf("%ld %ld %ld\n\n",maxsum,first+1,end+1);
else
printf("%ld %ld %ld\n",maxsum,first+1,end+1);
}
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询