51nod1090

来源:互联网 发布:js发送get请求参数 编辑:程序博客网 时间:2024/04/28 08:10

#include <iostream>
#include<algorithm>
using namespace std;
int binsearch(int a[],int n,int x)
{
    int low,high,mid;
    low=0;high=n-1;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(a[mid]==x)
        return 1;
        else if(a[mid]<x)
        low=mid+1;
        else
        high=mid-1;
    }
    return -1;
}                                     //二分模板
int num[1005];
int main()
{
    int t,n,i,j,sign;
    while(cin>>t)
    {
        sign=0;
        for(i=0;i<t;i++)
        cin>>num[i];
        sort(num,num+t);
        for(i=0;i<=t-3;i++)
        for(j=i+1;j<=t-2;j++)
        {
            n=0-num[i]-num[j];
            if(binsearch(num,t,n)!=-1&&n>num[j])
            {
                cout<<num[i]<<" "<<num[j]<<" "<<n<<endl;
                sign=1;
            }
        }
        if(sign==0)
        cout<<"No Solution"<<endl;
    }
    return 0;
}                                      //就是遍历两个数,之后二分查找第三个数
0 0