Loading [MathJax]/jax/input/TeX/jax.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >补题A-E Codeforces Round 953 (Div. 2)

补题A-E Codeforces Round 953 (Div. 2)

作者头像
WuShF
发布于 2025-02-26 00:13:06
发布于 2025-02-26 00:13:06
8300
代码可运行
举报
文章被收录于专栏:笔记分享笔记分享
运行总次数:0
代码可运行
在这里插入图片描述
在这里插入图片描述

A. Guess the Maximum

原题链接:https://codeforces.com/contest/1979/problem/A

求相邻元素的最大值的最小值。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
const int N = 2e5 + 5;
int n, m, k;
int a[N];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int minmx = 1e9;
    for (int i = 2; i <= n; i++) {
        minmx = min(minmx, max(a[i - 1], a[i]));
    }
    cout << minmx - 1 << endl;
}

int main() {
    IOS;
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

B. XOR Sequences

原题链接:https://codeforces.com/contest/1979/problem/B

因为异或运算满足两数相同为0,不同为1

期望是区间内的数ai = ia ^ x等于bi = ib ^ y

满足条件的所有iaib一定满足:ia ^ ib等于x ^ y

由于是求区间长度。寻找区间左端点,显然有无数对符合条件。

假如现在x ^ y等于z

那么ia ^ ib也应该等于z,并且ia + 1 ^ ib + 1也等于z

如果+1之后仍相等,那么低位+1时受影响的连续的10应该是相等的。

一直加到lowbit(z)那一位,再加会影响第lowbit(z) << 1位。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
const int N = 2e5 + 5;
int x, y;
int lowbit(int x) { return x & -x; }
void solve() {
    cin >> x >> y;
    cout << lowbit(x ^ y) << endl;
}

int main() {
    IOS;
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

C. Earning on Bets

原题链接:https://codeforces.com/contest/1979/problem/C

题目要求,期望收益大于成本。

  • the total amount of coins you bet on all outcomes must be strictly less than the number of coins received back for each possible winning outcome

假设每个点都投资1元,对于a[i],投资1元的期望收益是a[i]/n,总的期望收益是sum(a)/n

需要sum(a)/n>n,假如在a[i]上再多投资1元,那么期望收益为(sum(a)+a[i])/n需大于n+1

但如果没选到a[i]呢,损失会+1

改动一处,会影响多处,需要尝试换个角度,减少变量数量。

如果让a[i]赢,那么投资1元的收益是a[i],失败的损失是1,这个状态转移的难点在于,难以判断a[i]上投资增加之后,与其他a[j]上收益的关系。

  • 比如我在a[i]上多投资1元,可以影响多次下注,他们必须再多投资1元,获胜收益才能大于支出。而新的投资有可能影响其他的投资。

如果让a[i]赢,那么投资1/a[i]元的收益是1元。

现在固定收益,每个点获胜都是1元,那么成本为1/a[i], i in a

  • 如果当前方案可行,那么1大于1/a[i], i in n

假如此时不满足这个式子,那么要么提高收益,要么降低成本,显然提高收益的同时会提高成本,降低成本的同时会降低收益,假如此时成本为1.2

  • 要增加收益,那么每个点的收益都应大于1.2,那么分母也会放缩到1.2*1.2
  • 要减去成本,那么部分点获胜的收益会减少0.2*a[i],当该点获胜时,收益小于1,而此时总成本为1。如此递推,最终分子分母也会放缩成原来的1/1.2

1/a[i]未必是整数。最小的整数就是lcm(a),那么每个点的投资为lcm(a)/a[i]

期望的可行方案应满足:

  • lcm(a)大于sum(lcm(a)/a[i]) i in n
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
const int N = 2e5 + 5;
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n;
int a[N];

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ll L = 1;
    for (int i = 1; i <= n; i++)
        L = lcm(L, a[i]);
    ll S = 0;
    for (int i = 1; i <= n; i++)
        S += L / a[i];
    if (S >= L) {
        cout << "-1" << endl;
        return;
    }
    for (int i = 1; i <= n; i++) {
        cout << L / a[i] << " \n"[i == n];
    }
}

int main() {
    IOS;
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

D. Fixing a Binary String

原题链接:https://codeforces.com/problemset/problem/1979/D

题意是将一个01串分成左右两个部分,左边翻转之后追加到右边。

如果有合法的中断位置,那么,长度不等于k的连续0/1段至多两个。

翻转操作,可以拼接,断点前的最后一段和整串的最后一段,对其他段无影响。

分情况讨论即可。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
constexpr int N = 2e5 + 5;

int n, k;
string s;
int pre[N], suf[N];
void solve() {
    cin >> n >> k;
    cin >> s;
    if (k == n) {
        int cnt = count(s.begin(), s.end(), s.front());
        if (cnt == n)
            cout << n << endl;
        else
            cout << -1 << endl;
        return;
    }
    s = ' ' + s + ' ';
    pre[0] = suf[n + 1] = 1;
    for (int i = 1; i <= n; i++)
        pre[i] = pre[i - 1] && (i <= k || s[i] != s[i - k]);
    for (int i = n; i; i--)
        suf[i] = suf[i + 1] && (i >= n - k + 1 || s[i] != s[i + k]);
    int cnt = 1;
    for (int i = 2; i <= n; i++) {
        if (s[i] != s[i - 1])
            cnt = 1;
        else
            cnt++;
        if (cnt >= k && s[i] != s[i + 1]) {
            int p = i - k;
            if (!p || !pre[p] || !suf[p + 1])
                continue;
            int flag = 1;
            for (int j = n - k + 1; j <= n; j++) {
                int x = p - (j + k - n) + 1;
                if (x < 1)
                    break;
                if (s[x] == s[j]) {
                    flag = 0;
                    break;
                }
            }
            if (flag == 1) {
                cout << p << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
    return;
}
int main() {
    IOS;
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

E. Manhattan Triangle

原题链接:https://codeforces.com/contest/1979/problem/E

对于点i来说,曼哈顿距离为d的点,一定在一个以点i为中心,边长为2d的正方形边上。

画板
画板

假如正方形边框上又选定了图上这个点,那么第二点的合法点也是一个矩形,合法的交集为标注的边:

画板
画板

曼哈顿转切比雪夫,是将坐标系顺时针旋转45度,并放大2倍。

旋转前,第3点与前两点的距离都是d2

旋转后,由于放大了2倍,所以新的距离刚好是d。

预处理每条边,维护旋转后的横纵坐标和输入时的需要。

按新的横坐标分组并排序。

枚举每一个横坐标,他的点集应该在与x轴垂直的直线上。

  • 枚举点集的每个点,找纵坐标+d处的第2点。
  • 二分搜索左右两侧的区间,有没有合法的第三点。
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
const int N = 2e5 + 5;
using pii = pair<int, int>;
using aiii = array<int, 3>;
int n, d;
aiii p[N];
aiii ans;

void fuck() {
    map<int, set<pii>> mp;
    for (int i = 1; i <= n; i++) {
        mp[p[i][0]].insert({p[i][1], p[i][2]});
    }
    for (auto &x : mp) {
        set<pii> line1 = x.second;
        if (mp.count(x.first + d)) {
            set<pii> line2 = mp[x.first + d];
            for (pii it0 : line1) {
                int y1 = it0.first;
                auto it1 = line1.lower_bound({y1 + d, 0});
                if (it1 == line1.end() || it1->first != y1 + d)
                    continue;
                auto it2 = line2.lower_bound({y1, 0});
                if (it2 == line2.end() || it2->first > y1 + d)
                    continue;
                ans = {it0.second, it1->second, it2->second};
            }
        }
        if (mp.count(x.first - d)) {
            set<pii> line2 = mp[x.first - d];
            for (pii it0 : line1) {
                int y1 = it0.first;
                auto it1 = line1.lower_bound({y1 + d, 0});
                if (it1 == line1.end() || it1->first != y1 + d)
                    continue;
                auto it2 = line2.lower_bound({y1, 0});
                if (it2 == line2.end() || it2->first > y1 + d)
                    continue;
                ans = {it0.second, it1->second, it2->second};
            }
        }
    }
}

void solve() {
    cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        p[i] = {x + y, x - y, i};
    }
    ans = {};
    fuck();
    for (int i = 1; i <= n; i++)
        swap(p[i][0], p[i][1]);
    fuck();
    for (int x : ans)
        cout << x << ' ';
    cout << endl;
}
signed main() {
    IOS;
    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-02-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
补题A-D Educational Codeforces Round 166 (Rated for Div. 2)
对于前n位,修改abs(a[i] - b[i])次使a[i]变成b[i]是必须的。 对于第n+1位,如果在之前的修改过程中出现过,那么可以直接移过来,操作次数为1。 如果之前没出现过,那么就找一个离b[n+1]最近的。
WuShF
2025/02/19
940
补题A-D Educational Codeforces Round 166 (Rated for Div. 2)
Codeforces Round #784 (Div. 4)(A~F)
A. Division? Origional Link 题目大意 按照分数区间输出对应的难度。 思想: 签到题。 代码: #include <iostream> #include <cstring>
浪漫主义狗
2022/10/31
3110
Codeforces Round #674 (Div. 3)(A~D)
A. Floor Number ---- Origional Link 题目大意: 给定目标房间编号 n 及一层楼住户数量 x。 第一层楼只有 2 个住户,求目标房间所在楼层。 ---- 思想: 签到题。 n\le2 时在第一层。 n\gt 2 时: 若 x 可以整除 n-2,则在 \frac{n-2}{m} + 1 层; 反之在 \frac{n-2}{m} + 2 层。 ---- 代码: #include <iostream> #include <cstring> #include <cstdio
浪漫主义狗
2022/10/28
3730
Codeforces Round #677 (Div. 3)
显然,如果最大值和最小值相同,则肯定不满足题意。否则,一定存在一个值mx,它的左右两边存在一个小于它的数。此时,该位置的鱼满足题意。
dejavu1zz
2020/10/21
5760
Codeforces Round #677 (Div. 3)
Codeforces Round #826 (Div. 3)(A~D)
A. Compare T-Shirt Sizes ---- Origional Link 题目大意: 给定不同衬衫大小的尺寸编号如:S,M,L。 除 M 之外,X 作为尺寸前缀代表其倍数大小。 如:XXL\gt XL,XXS\lt XS。 给定两个代表衬衫尺寸的字符串,判断衬衫大小。 ---- 思想: 签到题。 判断模拟即可。 ---- 代码: #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #in
浪漫主义狗
2022/10/28
3190
AtCoder Beginner Contest 273(A~D)
A - A Recursive Function ---- Origional Link 题目大意: 求 f(k) 如下: f(0) = 1; f(k) = k \times f(k - 1) ---- 思想: 签到题。 ---- 代码: #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <sstream> #include <vector> #
浪漫主义狗
2022/10/28
3110
2022 年 CCPC 河南省赛 (A,E,F,G,H)
A. Mocha 上小班啦 ---- 原题链接 题目大意: 一个数由互不相同的 n 位数组成。 输出 n 位的满足上述条件的最小整数(不含前导零)。 不存在则输出 -1。 ---- 思想: 签到题。 当 n <= 10 时,最小的 当 n > 10 时不存在可以满足条件的数。 ---- 代码: #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <
浪漫主义狗
2022/10/08
9480
2022 年 CCPC 河南省赛 (A,E,F,G,H)
Codeforces Round #549(div1)简析
正解貌似有分四种情况什么的,我做时是发现各个起点其实都等价的,所以随便选一个起点,再暴举终点以暴举答案,更新即可。
ACM算法日常
2019/04/25
4250
Codeforces Round #560 (Div. 3)
给你n个数,这n个数是x的所有因子(除了1和x),若存在,则把n个数排序,任何对称的两个数之积就是,
用户2965768
2019/06/14
4110
河工院首届工业设计大赛程序组(挑战赛)题解
本题主要考察四舍五入,C语言中是四舍六入,但是需要四舍五入,则在结果后面加上0.001即可。
浪漫主义狗
2024/08/07
1010
河南工程学院2022级新生周赛(三)题解
A. 6男 ---- 原题链接 题目大意: 给定一个字符串 S,求最长的连续的 6 的字串的长度。 S 可能含有空格。 ---- 思想: 签到题。 读入时注意空格。 ---- 代码: #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <sstream> #include <vector> #include <queue> #include <stac
浪漫主义狗
2022/10/09
3050
【算法竞赛】Namomo Winter 2023 Day 3 Div 2
Dashboard - 2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest - Codeforces
Livinfly
2023/01/11
3610
【队伍训练】Codeforces Round #660 (Div. 2)
A 思维 #pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) typedef long long ll;
杨鹏伟
2020/09/11
3510
Codeforces Round 524(Div. 2)
需要邀请n个人来参加派对.需要制作邀请卡.一张邀请卡需要2红, 5绿, 8蓝. 每个笔记本有k个某种颜色.求最少需要多少个笔记本.
xiaohejun
2020/02/18
3100
相关推荐
补题A-D Educational Codeforces Round 166 (Rated for Div. 2)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验