Codeforces Round #706 Editorial

1496A. Split it!

类回文判断,只要 k = 0 或者 s[1,k]s[nk+1,n]是回文即可

特判情况 n < 2 * k + 1NO

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        string s;
        int n; ll k;
        cin >> n >> k;
        cin >> s;
        bool f = true;
        for (int i = 0; i < k && f; ++i) f = s[i] == s[n - i - 1]);

        cout << (f && n >= 2 * k + 1 ? "YES\n" : "NO\n");
    }
    return 0;
}

1496B. Max and Mex

模拟,当 mex(a) < max(b) 时 必有 a+b2<b 则集合不一样的数可增加一,否则每进行一次操作 + 1

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        int n;
        ll k;
        cin >> n >> k;
        vector<ll> a(n);
        set<ll> s;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            s.insert(a[i]);
        }
        sort(a.begin(), a.end());
        if (k == 0) {
            cout << s.size() << "\n";
            continue;
        }
        int i = 0;
        ll b = 0;
        while (b == a[i]) b++, i++;
        if (b <= a[n - 1]) {
            s.insert((b + a[n - 1] + 1) / 2);
            cout << s.size() << "\n";
            continue;
        }
        cout << s.size() + k << endl;
    }
    return 0;
}

1496C. Diamond Miner

将坐标绝对值化存入数组排序

(ac)2+(bd)2=a2+d2 要想有最小化,只能大值匹配大值

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    for (cin >> _; _--;) {
        int n;
        cin >> n;
        vector<int> xx, yy;
        for (int i = 0; i < 2 * n; ++i) {
            int x, y;
            cin >> x >> y;
            if (x == 0) yy.push_back(abs(y));
            else
                xx.push_back((abs(x)));
        }
        sort(xx.begin(), xx.end());
        sort(yy.begin(), yy.end());
        double cnt = 0.0;
        for (int i = 0; i < n; ++i) {
            cnt += sqrt(1.0 * xx[i] * xx[i] + 1.0 * yy[i] * yy[i]);
        }
        cout << setprecision(15) << cnt << "\n";
    }
    return 0;
}

1496D. Let's Go Hiking

学习自 洛绫璃 dalao的思路

这是一道博弈题

由于只能存在一条最长链,否则先手站一条, 后手站一条, 先手必输

其次, 只有一条最长链, 先手和后手都会选在最长链上, 否则谁不在, 另一方直接获胜

在其 先手会在山峰, 否则后手直接卡死

故先手会选择在 最长链的最高端, 后手会选择最长链最远的地方, 保证和先手相隔 偶数个位置(保证两者都走最长链, 后手胜)

后手保证了先手最长链一定会输, 只能走最长链的反方向, 比较先手和后手能走的长度, 判断是否能先手赢

const int N = 1e5 + 5;
int t, n, maxn, ans, a[N], p1[N], p2[N];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        p1[i] = (a[i] <= a[i - 1] || i == 1) ? 0 : (p1[i - 1] + 1);
        maxn = max(maxn, p1[i]);
    }
    for (int i = n; i >= 1; i--)
        p2[i] = (a[i] <= a[i + 1] || i == n) ? 0 : (p2[i + 1] + 1),
        maxn = max(p2[i], maxn);
    for (int i = 1; i <= n; i++)
        if (p1[i] == p2[i] && p1[i] == maxn && maxn > 0 && ((maxn & 1) == 0)) {
            ans = i;
            break;
        }
    for (int i = 1; i <= n; i++)
        if (ans != i && (p1[i] == maxn || p2[i] == maxn)) {
            ans = 0;
            break;
        }
    printf("%d", ans ? 1 : 0);
}
posted @   RioTian  阅读(90)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
历史上的今天:
2020-03-11 PTA | 1029 旧键盘 (20分)
2020-03-11 关于竞赛大佬常用的 static const auto _ = []() 用法解析
2020-03-11 LeetCode | 1013. 将数组分成和相等的三个部分
点击右上角即可分享
微信分享提示

📖目录