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:那位大牛帮我看一下,到底错在哪里?In Reply To:那位大牛帮我看一下,到底错在哪里? Posted by:200892458 at 2009-04-24 20:58:12 > #include<stdio.h> > #include<memory.h> > bool hasvalue[60001]; > bool divide(int *nums,int sum) > { > int temp,i,j,k,max=0; > hasvalue[0]=true; > for(i=0;i<6;i++) > { > if(nums[i]) > { > for(j=max;j>=0;j--) > if(hasvalue[j]) > { > temp=j; > if((temp+i+1>sum)||hasvalue[temp+i+1]) > continue; > for(k=0;k<nums[i];k++) > { > temp+=i+1; > if(temp>sum) > break; > hasvalue[temp]=true; > if(temp==sum) > return true; > } > if(temp>max) > max=temp; > if(max>sum) > max=sum; > } > } > } > if(hasvalue[sum]) > return true; > return false; > } > > int main() > { > memset(hasvalue,false,sizeof(hasvalue)); > int nums[6]={0},i,sum=0,ncase=1; > bool alleven; > while(1) > { > sum=0; > alleven=true; > for(i=0;i<6;i++) > { > scanf("%d",&nums[i]); > sum+=nums[i]*(i+1); > if(nums[i]%2!=0) > alleven=false; > } > if(sum==0) > return 0; > printf("Collection #%d:\n",ncase++); > if(alleven) > printf("Can be divided.\n"); > else if(sum%2!=0) > printf("Can't be divided.\n"); > else > { > if(divide(nums,sum/2)) > printf("Can be divided.\n"); > else printf("Can't be divided.\n"); > } > printf("\n"); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator