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. CLR via C# 笔记 -- 数组(16)

    1. 数组隐式继承 System.Array,所以数组是引用类型.变量包含的是对数组的引用,而不是包含数据本身的元素. 2. 数组协变性.将数组从一种类型转换为另一种类型. string[] sa = ...

  2. 35个Redis企业级性能优化点与解决方案

    Redis作为企业级应用中广泛使用的高性能键值存储数据库,其性能优化是一个复杂且多面的话题.以下是V 哥整理的一些关键的优化点和相应的解决方案,提供给兄弟们参考. Redis的性能优化涉及到硬件选择. ...

  3. I2S 总线学习:1-有关概念

    背景 I2S总线 是一种常见的总线,也是需要掌握的. 概念 I2S(Inter-IC Sound)总线, 又称 集成电路内置音频总线,是飞利浦公司为数字音频设备之间的音频数据传输而制定的一种总线标准, ...

  4. get基于报错的sql注入

    get基于报错的sql注入发现 Less1: sqli-labs第一关提示说在网页上输入id,也就是?id=1. 但这个?是什么意思,它表示index.php?也就是默认页面.然后?id=1就是把id ...

  5. 【点云检测】OpenPCDet 教程系列 [1] 安装 与 ROS运行

    前言与参考 主要是介绍库的使用,做笔记区 首先搜索的时候有个问题 一直在我脑子里 hhh 就是MMlab其实还有一个叫mmdetection3d 的库,然后搜的时候发现 hhh 有网友和我一样的疑惑: ...

  6. (转载)linux命令英文缩写的含义(方便记忆)

    linux常用命令的英文单词缩写 命令缩写: ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户rpm:redhat packa ...

  7. Windows 10 LTSC中个人版OneDrive失效的问题

    该问题是由于LTSC注册表无onedriver的id{A52BBA46-E9E1-435f-B3D9-28DAA648C0F6}定义导致,解决方案是新建一个reg_onedrive.reg文件,并编辑 ...

  8. Vue 数组和对象更新,但视图未更新,背后的故事

    在实际开发中,遇到遍历数组和对象,当property 发生改变时,并没有触发视图的更新今天来浅显的聊聊这背后的故事,有说的不对地方,还望指出! 本人博文地址:https://www.cnblogs.c ...

  9. 第一章 FFmpeg初体验:在Centos7.9下编译FFmpeg!

    FFmpeg 官方网站:https://ffmpeg.org//download.html#build-linux 1.下载源码 1.1 第一种方式,官网上面下载源码包: 截至目前最新的版本是7.0. ...

  10. C# 枚举帮助类EnumHelper(获取描述、名称和数值)

    帮助类定义 public class EnumHelper { #region 静态方法 public static Dictionary<string, string> GetEnumD ...