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:如此暴力的代码也WA??In Reply To:如此暴力的代码也WA?? Posted by:dynamic_study at 2009-08-31 16:40:18 > #include<iostream> > #include<algorithm> > using namespace std; > bool cmp(long a,long b) > {return a>b;} > long a[1001]; > int n; > int bins(long temp) > { > int left=0,right=n-1,mid; > while(left<=right) > { > mid=(left+right)>>1; > if(a[mid]<temp) > right=mid-1; > else if(a[mid]>temp) > left=mid+1; > else > return mid; > } > return -1; > > } > int main() > { > > int i,j,k; > long mid,ans; > bool loop; > while(scanf("%d",&n)!=EOF&&n){ > for(i=0;i<n;i++) > scanf("%ld",&a[i]); > sort(a,a+n,cmp); > loop=false; > if(n<4) > goto next; > for(i=0;i<n-2;i++) > { > for(j=i+1;j<n-1;j++) > { > for(k=j+1;k<n;k++) > { > mid=a[i]+a[j]+a[k]; > ans=bins(mid); > if(ans!=-1&&ans!=i&&ans!=j&&ans!=k) > { > loop=true; > goto next; > } > } > > } > } > next: > if(loop) > printf("%ld\n",mid); > else > printf("no solution\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