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 |
测试的结果都正确,就是WA,帮忙给你个关键的测试数据In Reply To:没辙了!帮忙看一下算法 Posted by:baipf at 2005-08-15 13:48:18 > #include<stdio.h> > #include<malloc.h> > > void quickSort(int *n); > int isFill(int lenth,int total); > int N; > int p=0; > int *num; > int sum=0; > > int main() > { > int i,max; > > scanf("%d",&N); > > while(N>0) > { > sum=0; > num=(int *)malloc(N*sizeof(int)); > for(i=0;i<N;i++) > { > scanf("%d",&num[i]); > sum=sum+num[i]; > } > quickSort(num); > > max=num[0]; > for(i=max;i<=sum;i++) > { > if(sum%i==0) > { > if(isFill(i,sum/i)) > { > printf("%d\n",i); > break; > } > } > } > free(num); > scanf("%d",&N); > } > > return 0; > } > > void quickSort(int n[]) > { > int i,j; > int temp; > for(i=0;i<N;i++) > for(j=i;j<N;j++) > { > if(n[i]<n[j]) > { > temp=n[i]; > n[i]=n[j]; > n[j]=temp; > } > } > } > int isFill(int lenth,int total) > { > int i,j,flag=0; > int *str; > str=(int *)malloc(total*sizeof(int)); > for(i=0;i<total;i++) > { > str[i]=lenth; > } > for(i=0;i<N;i++) > { > flag=0; > for(j=0;j<total;j++) > { > if(str[j]-num[i]>=0) > { > flag=1; > str[j]=str[j]-num[i]; > break; > } > } > if(flag==0) > { > free(str); > return 0; > } > } > free(str); > return 1; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator