题目链接
题目大意
你可以选择一连串的序列,把这一连串的序列变成他们的中位数。
给出长度为n的序列,给出要把这个序列最终变为的数k,问你能不能把序列最终变为k。
当你选的序列为偶数个时,中位数为较小的那个。
分析
最后全变成k要满足两个条件:
- 序列中至少要有一个数为k
- 序列中要有一种连续的三个数中至少有两个数大于等于k(有一个连续的三个数满足即可)
因为当你选的序列为偶数个时,中位数为较小的那个,那么如果满足条件2,一定会把其他数字变成比k大的数,然后在变化就行,一定可以成功,反之则不满足。
代码
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (ll i=a;i<=n;i++)
#define per(i,n,a) for (ll i=n;i>=a;i--)
#define pb push_back
//#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define INF 0x3f3f3f3f
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll, ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1e9 + 7 ;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int maxn = 1e5 + 10;
int a[maxn];
int main(){
int T;
scanf("%d", &T);
while(T--){
int n, k, flag = 0;
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
if(a[i] == k){
flag = 1;
}
}
if(flag == 0){
printf("no\n");
continue;
}
else{
if(n == 1){
printf("yes\n");
continue;
}
}
flag = 0;
for(int i = 1; i < n; i++){
if(a[i] >= k){
if(a[i + 1] >= k || (a[i + 2] >= k && i + 2 <= n)){
flag = 1;
break;
}
}
}
if(flag){
printf("yes\n");
}
else{
printf("no\n");
}
}
return 0;
}