SMU Autumn 2023 Round 3(Div.1)

A. Find The Array

要满足“b数组内任意一个元素满足可以被数组两边的元素整除”这个条件,我们很容易想到1是万能的,所以我们只需要把a数组某些元素改成1就可以了

条件二要满足a,b方差够小,那其实我们只用把a数组内奇数位,偶数位分别相加对比,如果偶数位和大,就把奇数位改成1,如果奇数大则相反

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> a(n + 1);
i64 sum1 = 0, sum2 = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i & 1)sum1 += a[i];
else sum2 += a[i];
} if (sum1 < sum2) {
for (int i = 1; i <= n; i += 2)
a[i] = 1;
} else {
for (int i = 2; i <= n; i += 2)
a[i] = 1;
} for (int i = 1; i <= n; i++)
cout << a[i] << " \n"[i == n]; }
return 0;
}

B. Busy Robot

题意是机器人初始在一数轴上的原点 某时刻接受命令 并朝命令方向前进 每秒前进\(1\)距离 在未到达当前命令的终点时 忽略当前时刻的其他命令若机器人在 \([ t_i , t_{i + 1} ]\)时间内移动到 \(x_i\) 位置 视为完成一次指令 (被忽略的命令可能会成功执行),给出一系列的指令问机器人能完成多少次

记录每次指令的起点 \(st\) 和终点\(ed\) 下一次停止的时间 \(next\) 上一次接收到可执行命令的时刻 \(last\),遍历每个指令 如果当前指令的时刻大于等于 \(next\)说明可以执行当前指令 更新 \(next,st,ed,last\),否则判断机器人是否能在 \([ t_i , t_{ i + 1} ]\)时间内移动到 \(x_i\) 位置具体判断依据为 在 \(t_i\) 时刻 到 \(t_{i+1}\)时刻机器人是否经过 \(x_i\)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<i64> tim(n + 1), pos(n + 1);
for (int i = 0; i < n; ++i)
cin >> tim[i] >> pos[i];
tim[n] = 1e10; i64 next = 0, st = 0, ed = 0, last = 0, res = 0; for (int i = 0; i < n; ++i) {
if (tim[i] >= next) { next = tim[i] + abs(pos[i] - ed);
st = ed, ed = pos[i];
last = i;
if (next <= tim[i + 1])
res++;
}
else {
if (st >= ed) {
int y = st - (tim[i] - tim[last]);
int x = max(ed, st - (tim[i + 1] - tim[last]));
if (pos[i] >= x && pos[i] <= y)res++;
}
else {
int x = st + (tim[i] - tim[last]);
int y = min(ed, st + tim[i + 1] - tim[last]);
if (pos[i] >= x && pos[i] <= y)res++;
}
}
}
cout << res << endl; }
return 0;
}

C. Building a Fence

题意是用 \(n\) 个宽度为 \(1\) 高度为 \(k\) 的木板构建一段栅栏,第 \(i\) 个木板下面的地面高度等于 \(h_i\),第一个和最后一个木板必须在地面上,其他的木板 底端 可能位于地面或者不高于地面 \(k-1\)的高度上,相邻的两个木板必须有公共边,也即有重合的部分,问有没有可能建造一个符合所有规则的围栏

设 \(l,r\) 分别为当前栅栏下端的最小高度和最大高度,因为每段栅栏高度都为 \(k\),可知下一段栅栏底边高度的范围为 $[ l − k + 1 , r + k − 1 ] $,又因为栅栏底边最低要在地上,即 \(a[i]\) 最高只能达到 \(a[i] + k - 1\), 所以我们可维护\(l = max(l - k + 1, a[i])\),\(r = min(r + k - 1, a[i] + k - 1)\),如果 \(l \leq r\) 说明可行,否则不可行,最后特判一下最后一块栅栏(只能建造在地上),即判断一下 \(a[n]\) 是否在 \([ l , r ]\) 的范围内

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
cin >> a[i]; bool flag = true;
int l = a[1], r = a[1]; for (int i = 2; i <= n; ++i) {
l = max(l - k + 1, a[i]);
r = min(r + k - 1, a[i] + k - 1);
if (l > r) {
flag = false;
break;
}
}
if (a[n] < l || a[n] > r)
flag = false; cout << (flag ? "YES\n" : "NO\n"); }
return 0;
}

D. Program

只要求出每个前缀和每个后缀和变换过程能得到的最大值和最小值,就可以求出总体变换过程中的上界下界,然后就得出变换数字的个数。

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
vector<i64> pre(n + 2), pre_mi(n + 2), pre_mx(n + 2);
vector<i64> suf(n + 2), suf_mi(n + 2), suf_mx(n + 2);
string s;
cin >> s;
s = " " + s; for (int i = 1; i <= n; i++) {
int now = 1;
if (s[i] == '-') now = -1;
pre[i] = pre[i - 1] + now;
pre_mi[i] = min(pre_mi[i - 1], pre[i]);
pre_mx[i] = max(pre_mx[i - 1], pre[i]);
}
suf[n + 1] = suf_mi[n + 1] = suf_mx[n + 1] = 0;
for (int i = n; i >= 1; i--) {
int now = 1;
if (s[i] == '-') now = -1;
suf[i] = suf[i + 1] + now;
suf_mx[i] = max(0ll, suf_mx[i + 1] + now);
suf_mi[i] = min(0ll, suf_mi[i + 1] + now);
} for (int i = 1; i <= m; i++) {
int l, r;
cin >> l >> r;
i64 mx = 0, mi = 0;
mx = max(mx, pre_mx[l - 1]);
mi = min(mi, pre_mi[l - 1]);
int res = pre[l - 1];
mx = max(mx, suf_mx[r + 1] + res);
mi = min(mi, suf_mi[r + 1] + res);
cout << mx - mi + 1 << '\n';
} }
return 0;
}

SMU Autumn 2023 Round 3(Div.1)的更多相关文章

  1. Codeforces Round #845 (Div. 2) and ByteRace 2023 A-D

    Codeforces Round #845 (Div. 2) and ByteRace 2023 A-D A. Everybody Likes Good Arrays! 题意:对给定数组进行操作:删除 ...

  2. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. Mirror多人联网发布阿里云

    Mirror多人联网发布阿里云 新建模板小书匠 将mirror网络地址和端口选为你阿里云服务器上开放的公网地址和端口 IP与端口 2. 在阿里云服务器安全组中开放你所制定的端口 开放阿里云端口 3. ...

  2. 如何使用csproj构建C#源代码组件NuGet包?

    一般我们构建传统的NuGet包,都是打包和分发dll程序集文件. 至于打包和分发C#源代码文件的做法,比较少见. 那么这种打包源代码文件的做法,有什么优点和缺点呢? 优点: 方便阅读源代码. 方便断点 ...

  3. Python 压缩PDF减小文件大小

    压缩 PDF 文件能有效减小文件大小并提高文件传输的效率,同时还能节省计算机存储空间.除了使用一些专业工具对PDF文件进行压缩,我们还可以通过 Python 来执行该操作,实现自动化.批量处理PDF文 ...

  4. 集成学习与随机森林(四)Boosting与Stacking

    Boosting Boosting(原先称为hypothesis boosting),指的是能够将多个弱学习器结合在一起的任何集成方法.对于大部分boosting方法来说,它们常规的做法是:按顺序训练 ...

  5. 记录EF 排序配上自定义的比较器

    记录EF 排序配上自定义的比较器 前言 要求页面文件显示的时候能够按照序号去排序要求如下: 数据库有一个列存放文件名,如: 1.1文件 1.2文件 1.1.1文件 1.1.11文件1.0.txt 1. ...

  6. 使用Scrcpy 在电脑显示手机画面并控制安卓设备

    使用Scrcpy 显示手机画面并控制手机 原文(有删改):https://www.iplaysoft.com/scrcpy.html 背景 本文适用于安卓开发人员,不针对普通安卓手机用户. 在安卓开发 ...

  7. 我对《RAG/大模型/非结构化数据知识库类产品》技术架构的思考、杂谈

    1.前言 在6.28/29的稀土掘金开发者大会RAG专场上,我们公司CEO员外代表TorchV分享了我们在<RAG在企业应用中落地的难点与创新> 其中最后分享了两个观点: AI在应用场景落 ...

  8. DAX 自动生成日期表-与订单表(业绩表)相同日期区间

    日期表 = ADDCOLUMNS ( CALENDAR (MIN('业绩表'[日期]), MAX('业绩表'[日期])), //关键在于MIN函数和MAX函数的使用 "年度", Y ...

  9. P6626 题解

    有一个很暴力的解法,就是以询问点为根 DFS. 考虑优化,我们考虑优化换根. 当根节点从父亲移动到它的某个孩子时,孩子的子树内所有点深度减 \(1\) 其余点深度加 \(1\). 同理,当根节点从某个 ...

  10. yb课堂之高并发项目必备利器之分布式缓存和本地缓存 《十九》

    什么是缓存? 程序经常要调用的对象存储在内存中,方便其使用时可以快速调用,不必去数据库或者其他持久化设备中查询,主要就是提高性能 DNS.前端缓存.代理服务器缓存Nginx.应用程序缓存(本地缓存.分 ...