Codeforces Round #710 (Div. 3)个人简单题解

补题链接:Here

Proble-A. Strange Table

根据 x 确定坐标确定的行数和列数。

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _;
    for (cin >> _; _--;) {
        ll n, m, x;
        cin >> n >> m >> x;
        x--;
        ll col = x / n, row = x % n;
        cout << row * m + col + 1 << "\n";
    }
    return 0;
}

Problem-B. Partial Replacement

题意:n组样例,每组单走一个字符串s,s由‘*’和‘.’组成,可以把'*'号变成‘X'号,但是需要满足,首尾的‘.’号要变成‘X’号,相邻'X'距离不能超过k。求最终X个数最小值。

长度很小,直接暴搜,找到*号之后,下一个位置从x+k开始倒着找,找到最后直接返回,这样肯定是最小的了。

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _;
    for (cin >> _; _--;) {
        int n, k;
        string s;
        cin >> n >> k >> s;
        int cnt = 1;
        int i = s.find_first_of('*');

        while (true) {
            int j = min(n - 1, i + k);
            for (; i < j and s[j] == '.'; --j)
                ;
            if (i == j) break;
            i = j, cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

Problem-C. Double-ended Strings

两个字符串不大,可暴力

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _;
    for (cin >> _; _--;) {
        string a, b;
        cin >> a >> b;
        int cnt = 0;
        int n = a.size(), m = b.size();
        for (int len = 1; len <= min(n, m); ++len) {
            for (int i = 0; i + len <= n; ++i)
                for (int j = 0; j + len <= m; ++j)
                    if (a.substr(i, len) == b.substr(j, len))
                        cnt = max(cnt, len);
        }
        cout << n + m - 2 * cnt << '\n';
    }
    return 0;
}

Problem-D. Epic Transformation

这里要用一下优先队列去模拟消除的过程。

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    int _;
    for (cin >> _; _--;) {
        int n, x;
        cin >> n;
        map<int, int> mp;
        priority_queue<pair<int, int>> q;
        for (int i = 0; i < n; ++i) {
            cin >> x;
            mp[x]++;
        }
        for (auto [x, y] : mp) q.push({y, x});
        int Size = n;
        while (q.size() >= 2) {
            auto [cnt1, x1] = q.top();
            q.pop();
            auto [cnt2, x2] = q.top();
            q.pop();
            cnt1--, cnt2--, Size -= 2;
            if (cnt1) q.push({cnt1, x1});
            if (cnt2) q.push({cnt2, x2});
        }
        cout << Size << "\n";
    }
    return 0;
}

Problem-E. Restoring the Permutation

E题待补...

posted @   RioTian  阅读(66)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
点击右上角即可分享
微信分享提示

📖目录