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 |
这题能用递归做吗,请牛人指点下哪错了#include<iostream.h> int a[16]; void Sort(int *,int); int find(int,int); void main(){ int num,s,n,i,j,sum; cin>>num; for(i=0;i<num;i++){ cin>>s>>n; sum=0; for(j=0;j<16;j++) a[j]=0; for(j=0;j<n;j++){ cin>>a[j]; sum=a[j]*a[j]+sum; if(a[j]==1) a[j]=0; } Sort(a,16); if((find(s,s)==1)&&(sum==(s*s))) cout<<"KHOOOOB!"<<endl; else cout<<"HUTUTU!"<<endl; } } int find(int s1,int s2){ int s,i,j,s3,r=0; if(s1>s2) s=s2; else s=s1; for(i=0;i<16;i++){ if((s>=a[i])&&(a[i]!=0)){ s3=a[i]; for(j=i;j<15;j++) a[j]=a[j+1]; a[15]=0; i=15; r=1; } } if(r==0) return 0; if(a[0]==0) return 1; if(s3!=s1){if(find(s1-s3,s2)==1) return 1;} if(s3!=s2){if(find(s2-s3,s1)==1) return 1;} if((s3!=s1)&&(s3!=s2)){if(find(s2-s3,s1-s3)==1) return 1;} return 0; } void Sort(int* a, int dimension) { int i,j; int tmp; for (i=0; i<dimension-1; i++) { for (j=i+1; j<dimension; j++) { if (a[i] < a[j]) { tmp=a[i]; a[i]=a[j]; a[j]=tmp;} } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator