最后一组拿不到通过
查看原帖
最后一组拿不到通过
843406
sjm2022楼主2024/5/18 18:23
#include<bits/stdc++.h>
using namespace std;

bool erfen(int *a,int l, int r,int mubiao)
{
    int  m=-1;
    while(l<r)
    {
        m=(r+l)/2;
        if(a[m]<mubiao)
        {
            l=m+1;
        }
        else if(a[m]>mubiao)
        {
            r=m-1;
        }
        else
        {
            return true;
        }

        if(a[l]==mubiao || a[r]==mubiao)
        {
            return true;
        }
    }

    if(a[l]==mubiao || a[r]==mubiao)
        {
            return true;
        }

    return false;

}

int main()
{
    int t, id;
    cin >> t>>id;

    for(int i=0; i<t; i++)
    {
        int n;
        cin >> n;

        int a[1000001];

        memset(a,0,n);
        for(int j=0; j<n; j++)
        {
            //一组数据录入
            cin>>a[j];
        }

        //排序
        sort(a, a+n);

        if(n<4)
        {
            cout<<"No"<<endl;
            continue;
        }

        if(id==4)
        {
            cout<<"Yes"<<endl;
            continue;
        }

            bool yes=false;
            for(int xiao = n-2; xiao>0; xiao--)
            {
                int cha = abs(a[xiao] - a[0]);
                if(erfen(a, 1, xiao-1, abs(a[n-1]-cha)))
                {
                    yes=true;
                    break;
                }
            }

            if(yes)
            {
                cout<<"Yes"<<endl;
            }
            else
            {
                cout<<"No"<<endl;
            }


    }
    return 0;
}

2024/5/18 18:23
加载中...