Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:谁给我看看代码,结果Runtime Error,算法贪心,自己运行没问题!!!In Reply To:谁给我看看代码,结果Runtime Error,算法贪心,自己运行没问题!!! Posted by:xtu716 at 2007-07-22 10:57:09 > #include <stdio.h> > #include <math.h> > > void main() > { > int MAX,a1,min,i,j,k,end[50000][2],max=0; > int N,M,day[50000]; > double add=0.0; > scanf("%d %d",&N,&M); > for(i=0;i<N;i++) > scanf("%d",&day[i]); > for(i=0;i<N;i++) > add += day[i]; > add /=M; > for(i=0;i<N;i++) > if(max<day[i]) > max=day[i]; > if(max<add)max=add; > MAX=max; > for(i=0;i<N-1;i++) > { > end[i][0] = day[i] + day[i+1]; > end[i][1] = abs(max - end[i][0]); > } > for(i=0;i<N-M;i++) > { > int YI=0; > for(j=0;j<N;j++) > if(end[j][0]<=MAX&&end[j][0]>0) > {YI++;j++;} > if(YI>=N-M-i)break; > > for(j=0,min=end[j][1];j<N-1;j++) > { > if(min>end[j][1]) > { > min=end[j][1]; > a1=j; > } > } > if(day[j]>MAX) > MAX=day[j]; > for(k=j+1;day[k]==0;k++); > day[j]+=day[k]; > day[k]=0; > for(k++;day[k]==0;k++); > end[j][0] = day[j] + day[k]; > end[j][1] = abs(max - end[j][0]); > } > printf("%d",MAX); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator