38. CF-Orac and Medians

链接

官方题解有严谨的证明。这里只写个思路。

  1. 显然 k 必须存在于原数组中
  2. 只要有连续两个 k,就可以完成任务
  3. 小的数容易同化大的数
  4. 考虑相对于 k 的大小关系
  5. k 的附近存在不小于它的数就可以了
  6. 考虑间距,要让中位数变大,必须是 k 的数多,<k 的数少的情况
  7. 那么必须存在一对 k 的数,它们的间距不超过 1
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& i : a) cin >> i;
    bool ok = false;
    for (auto& i : a) {
        ok |= (i == k);
        i = (i >= k);
    }
    if (!ok) {
        cout << "no\n";
        return;
    }
    ok = (n == 1);
    for (int i = 0; i + 1 < n; ++i) {
        if (a[i] && a[i + 1])
            ok = true;
    }
    for (int i = 0; i + 2 < n; ++i) {
        if (a[i] && a[i + 2])
            ok = true;
    }
    cout << (ok ? "yes\n" : "no\n");
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    double a = 3400, b = 127000;
    cout << a / b << endl;
}
posted @   Theophania  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2021-03-12 P3966 [TJOI2013]单词
点击右上角即可分享
微信分享提示