天天看點

Orac and Medians

​​D - Orac and Medians​​

參考:​​Codeforces Round #641 Div1.B Orac and Medians 中文題解​​

解題的關鍵在于,要找到其中的規律,然後就可以直接暴力了。

感覺找規律的技巧在于——對解決方法進行分類即可,以小化大。

// Created by CAD on 2020/5/12.
#include <bits/stdc++.h>
using namespace std;

const int maxn=1e5+5;
int a[maxn],b[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;cin>>t;
    while(t--){
        int n,k;cin>>n>>k;
        bool flag=0;
        for(int i=1;i<=n;++i) {
            cin>>a[i];
            if(a[i]<k) b[i]=-1;
            else if(a[i]==k) b[i]=0,flag=1;
            else b[i]=1;
        }
        if(flag){
            if(n==1){
                puts("yes");
                continue;
            }
            flag=0;
            for(int i=1;i<=n;++i){
                if(b[i]<0) continue;
                for(int j=i;j<=i+2;++j)
                    if(j>n) continue;
                    else if(i==j) continue;
                    else if(b[j]>=0) flag=1;
            }
            puts(flag?"yes":"no");
        }
        else puts("no");
    }
    return 0;
}