社区讨论

最后一组拿不到通过

P10444「MYOI-R3」极差参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lwbynuyr
此快照首次捕获于
2024/05/18 18:23
2 年前
此快照最后确认于
2024/05/18 20:49
2 年前
查看原帖
CPP
#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;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...