SMU Autumn 2023 Round 3(Div.1)
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)的更多相关文章
- 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! 题意:对给定数组进行操作:删除 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 小米便签AS部署之Git的基本使用
1 项目测试截图 及仓库地址 https://gitee.com/magicfatblink/Notes-master 2 小米便签代码的移植 2.1 IDE 的准备 2.1.1 AS版本选择 由于小 ...
- BST-splay板子 - 维护一个分裂和合并的序列
splay 均摊复杂度 \(O(\log n)\) 证明: https://www.cnblogs.com/Mr-Spade/p/9715203.html 我这个 splay 有两个哨兵节点,分别是1 ...
- QT学习:04 代码化的界面绘制
--- title: framework-cpp-qt-04-代码化的界面绘制 EntryName: framework-cpp-qt-04-ui-design-by-code date: 2020- ...
- power bi 如何删除敏感度标签
经验证,此方法不够彻底,我的office excel打开后还是要添加敏感度标签,即使我把敏感度标签删掉也不行. 当我把创建敏感度标签的管理员账户删掉之后,虽然打开excel还是会显示敏感度标签,但是已 ...
- Spark3学习【基于Java】2. Spark-Sql核心概念
SparkSession 从Spark2开始,Spark-SQL引入了SparkSession这个核心类,它是处理DataSet等结构数据的入口.在2.0之前,使用的是spark-core里的Spar ...
- ComfyUI基础篇:为什么要学 ComfyUI?
前言: 在AI生成图像领域,有许多产品,例如 Midjourney 和 Stability AI 等.为什么要学习 ComfyUI 呢?我斗胆带大家一起分析一下. 目录 1.Midjourney VS ...
- new操作符具体干了什么呢?
new操作符的作用如下: 1.创建一个空对象2.由this变量引用该对象3.该对象继承该函数的原型4.把属性和方法加入到this引用的对象中5.新创建的对象由this引用,最后隐式地返回this.过程 ...
- 从基础到高级应用,详解用Python实现容器化和微服务架构
本文分享自华为云社区<Python微服务与容器化实践详解[从基础到高级应用]>,作者: 柠檬味拥抱. Python中的容器化和微服务架构实践 在现代软件开发中,容器化和微服务架构已经成为主 ...
- oeasy教您玩转vim - 7 - # 从头插入
另存与保存 回忆上节课内容 上次我们学会了另存为命令 : saveas {file} 还有这个直接保存命令 : w 真的可以把修改存了 下面我们来研究插入命令的细节. 插入命令 首先我们可以查询这个插 ...
- oeasy教您玩转python - 001 - # 换行插入
先跑起来 Python 什么是 Python? Python 很好用 适合初学者 而且在各个领域都很强大 后来居上 上图可以点开 python3 早已有之 最终逆风翻盘 当然 java 也 ...