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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- FFmpeg开发笔记(三十一)使用RTMP Streamer开启APP直播推流
RTMP Streamer是一个安卓手机端的开源RTMP直播推流框架,可用于RTMP直播和RTSP直播,其升级版还支持SRT直播(腾讯视频云就采用SRT协议).RTMP Streamer支持的视频编 ...
- python + pytestTestreport生成测试报告_报告没有生成图标和报告样式错乱
pytestreport 生成测试报告的问题 1.生成报告html页面的样式错乱 2.生成报告html页面的图标没有展示 3. 生成报告html页面的查询详情按钮点击没有相应 问题排除: 浏览器开发者 ...
- mac brew install Error: No available formula with the name “*“的解决办法
背景 在mac上使用brew安装软件发生错误 解决办法 执行以下命令即可 rm -rf /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core ...
- 【Vyos-开源篇-1】- VMware 安装 VyOS 虚拟机
文章说明:使用VMware ESXi和VMware Workstation安装vyos软路由. 一.项目准备 1.1.VMware ESXi 我家里的是一台8核心,20G内存,2T的N5105工控机, ...
- 让matplotlib在绘图时显示中文
让matplotlib绘图时显示中文. 安装中文字体 apt install fonts-wqy-microhei 清除matplotlib的缓存 rm -rf ~/.cache/matplot ...
- 单片机升级,推荐此79元双核A7@1.2GHz国产平台的8个理由
含税79元即可运行Linux操作系统 对于嵌入式软件开发者而言,单片机令人最痛苦的莫过于文件操作.79元T113-i工业核心板(基于全志国产处理器,国产化率100%)可运行Linux操作系统,可使用L ...
- Unity中正面视图的相机最大距离定位
问题背景: Unity中在场景中有这样的需求,就是俯视整个场景或者平视整个场景.这种情况下场景中物体长宽比不一定和相机视口长宽比一致,要保证所有的物体都在视口内,并且距离不能太远,,所以处理起来需要点 ...
- Oracle 字符串分割,并将内码转中文(简单实现),项目实战
导读 实际项目开发过程中,可能会遇到这种情况,A表中A1字段存储B表中的内码如(1,2,3),此时需要将A表中的A1字段转中文,为了方便理解,我们这里创建学生表和老师表,一个学生对应N个老师. 创建表 ...
- 2024 年 Visual Studio 实用插件集合
前言 在软件开发领域,选择正确的工具可以极大地提升开发效率和质量. Visual Studio作为微软推出的强大集成开发环境(IDE),通过安装合适的插件,可以进一步增强其功能,满足开发者多样化的需求 ...
- Grafana Loki查询加速:如何在不添加资源的前提下提升查询速度
Grafana Loki查询加速:如何在不添加资源的前提下提升查询速度 来自Grafana Loki query acceleration: How we sped up queries withou ...