Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 如此暴力的代码也WA？？

Posted by dynamic_study at 2009-08-31 16:40:18 on Problem 2549 and last updated at 2009-08-31 16:41:37
```#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: