比赛链接:Here

1547A. Shortest Path with Obstacle

3个点 \(A,B,F\) ,前提 \(F\) 点为不可经过点,问 \(A\to B\) 最短路径长度


A题没什么难度,注意同列和同行在两者之间的情况即可

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int s = abs(a - c) + abs(b - d);
if (a == c && a == e && (f > b && f < d || f > d && f < b) || b == d && b == f && (e > a && e < c || e > c && e < a))
s += 2;
cout << s << '\n';
}
}

1547B. Alphabetical Strings

构造出一个按 字母序的字符串

  • 首先,构造空串
  • 重复 \(n\) 次:\(s:=c + s\) or \(s: = s + c\)

  • 首先,我们如果可以找出字母“a”在字符串s中的位置。如果这个位置不存在,那么答案是 NO

  • 假设这个位置存在并且等于 \(pos_a\)。让我们创建两个指针L和R。最初 \(L:=pos_a\),\(R:=L\)。我们将尝试使用语句中的算法来左右构建字符串 \(s\)

    当我们能迭代 \(n\) 次时输出 YES,否则 输出 NO

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
function<int(string)> check = [&](string s) {
if (s.empty())return 1;
if (s[0] == 'a' + s.size() - 1)return check(s.substr(1));
if (s.back() == 'a' + s.size() - 1)return check(s.substr(0, s.size() - 1));
return 0;
};
string s; cin >> s;
cout << (check(s) ? "YES\n" : "NO\n");
}
}

1547C. Pair Programming

一项工作有 Monocarp 和 Polycarp 两人各 \(n\) 和 \(m\) 工时合作完成

他们都有两种操作:

  • 0,新添加一行
  • x > 0 ,在第 x 行上修改为 x

但这项工作原本已经存在 \(k\) 行被完成,请 Monocarp 和 Polycarp 操作的任何正确公共序列,如果不存在则输出 -1


模拟,

对于两人的操作 \(x\) 是不能超过 \(k\) 的,所以使用双指针模拟两人的操作即可

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int k, n, m;
cin >> k >> n >> m;
vector<int>a(n), b(m), ans;
for (int &x : a)cin >> x;
for (int &x : b)cin >> x;
for (int i = 0, j = 0; i < n or j < m;) {
if (i < n and a[i] <= k) {
k += a[i] == 0;
ans.push_back(a[i++]);
} else if (j < m and b[j] <= k) {
k += b[j] == 0;
ans.push_back(b[j++]);
} else break;
} if (ans.size() != n + m)cout << "-1\n";
else {
for (int i : ans)cout << i << " ";
cout << "\n";
}
}
}

1547D. Co-growing Sequence

  • 如同 \([2,3,15,175]_{10} \to [10_2,11_2,1111_2,10101111_2]\)

    $[0,0,0] \to [0_2,0_2,0_2] $

    均为增长序列

现在给一个长度为 \(n\) 的 \(x_i\) 数组,请输出一组 \(y_i\) 使得 \(x_i ⊕ y_i\) 为增长序列


思路待补

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; cin >> n;
int x, p = 0;
for (int i = 0; i < n; ++i) {
cin >> x;
cout << (p | x) - x << " ";
p |= x;
}
cout << "\n";
}
}

1547E. Air Conditioners

对于每个位置的空调的最小值来说肯定是和左右(+1)比较

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, k;
cin >> n >> k;
vector<int> a(n, 2e9), v(k), t(k);
for (int &x : v) cin >> x;
for (int &x : t) cin >> x;
for (int i = 0; i < k; ++i)a[v[i] - 1] = t[i];
for (int i = 1; i < n; ++i) a[i] = min(a[i - 1] + 1, a[i]);
for (int i = n - 2; i >= 0; --i)a[i] = min(a[i + 1] + 1, a[i]);
for (int x : a)cout << x << " ";
cout << "\n";
}
}

1547F. Array Stabilization (GCD version)

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, d = 0;
cin >> n;
vector<int> v(n * 2);
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i + n] = v[i];
d = __gcd(d, v[i]);
}
int ans = 0;
vector<pair<int, int>>vt;
for (int i = 2 * n - 1; i >= 0; i--) {
vector<pair<int, int>> wp;
vt.push_back({0, i});
for (auto [x, y] : vt) {
x = __gcd(x, v[i]);
if (not wp.empty() and x == wp.back().first) wp.back().second = y;
else wp.push_back({x, y});
}
swap(vt, wp);
if (i < n) ans = max(ans, vt[0].second - i);
}
cout << ans << "\n";
}
}

1547G. How Many Paths?

邻接表 + 树形DP

【AC Code】

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, m;
cin >> n >> m;
vector<vector<int>> G(n), H(n);
for (int i = 0, u, v; i < m; i += 1) {
cin >> u >> v;
u -= 1;
v -= 1;
G[u].push_back(v);
H[v].push_back(u);
}
vector<int> order, id(n);
function<void(int)> dfs1 = [&](int u) {
id[u] = -1;
for (int v : H[u])
if (not id[v])dfs1(v);
order.push_back(u);
};
for (int i = 0; i < n; i += 1) if (not id[i]) dfs1(i);
reverse(order.begin(), order.end());
int count = 0;
function<void(int)> dfs2 = [&](int u) {
id[u] = count;
for (int v : G[u])
if (not ~id[v])
dfs2(v);
};
for (int i : order) if (not ~id[i]) {
dfs2(i);
count += 1;
}
vector<vector<int>> g(count);
for (int i = 0; i < n; i += 1)
for (int j : G[i]) {
g[id[i]].push_back(id[j]);
assert(id[i] >= id[j]);
}
vector<int> dp(count);
for (int i = id[0]; i >= 0; i -= 1) {
if (i == id[0]) dp[i] = 1;
if (dp[i]) {
for (int j : g[i]) if (j == i) dp[i] = -1;
}
for (int j : g[i]) {
if (dp[i] == -1) dp[j] = -1;
if (dp[i] == 2 and dp[j] != -1) dp[j] = 2;
if (dp[i] == 1 and dp[j] != -1 and dp[j] <= 1) dp[j] += 1;
}
}
for (int i = 0; i < n; i += 1) cout << dp[id[i]] << " ";
cout << "\n";
}
}

Codeforces Round #731 (Div. 3) A~G 解题记录的更多相关文章

  1. 刷题记录:Codeforces Round #731 (Div. 3)

    Codeforces Round #731 (Div. 3) 20210803.网址:https://codeforces.com/contest/1547. 感觉这次犯的低级错误有亿点多-- A 一 ...

  2. Educational Codeforces Round 47 (Div 2) (A~G)

    目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...

  3. Educational Codeforces Round 46 (Div 2) (A~G)

    目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...

  4. Educational Codeforces Round 45 (Div 2) (A~G)

    目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph ...

  5. Codeforces Round #306 (Div. 2) D.E. 解题报告

    D题:Regular Bridge 乱搞. 构造 这题乱搞一下即可了.构造一个有桥并且每一个点的度数都为k的无向图. 方法非常多.也不好叙述.. 代码例如以下: #include <cstdio ...

  6. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  7. Codeforces Round #582 (Div. 3)-G. Path Queries-并查集

    Codeforces Round #582 (Div. 3)-G. Path Queries-并查集 [Problem Description] 给你一棵树,求有多少条简单路径\((u,v)\),满足 ...

  8. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  9. 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations

    题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...

  10. Codeforces Round #368 (Div. 2)

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

随机推荐

  1. 4. Shell 循环语句

    重点: 条件测试. read. Shell 环境配置. case. for. find. xargs. gzip,bzip2,xz. tar. sed. 1)循环 1.1)循环执行介绍 将某代码段重复 ...

  2. uni-app学习笔记——路由与页面跳转

    小颖最近在学习小程序,怕自己前看后忘,毕竟还没开始进入项目实践中,就自己瞎倒腾嘻嘻,今天来看下  uni-app  的路由与页面跳转,小颖就简单列举下它们的用法,具体的大家可以看官网哦!啦啦啦啦啦  ...

  3. jdk所有版本-自留收藏

    链接:https://pan.baidu.com/s/1NDbEAEbKeh8xFzjEwB8aLg 提取码:0000

  4. Springboot+shiro,完整教程,带你学会shiro

    您的第一个 Apache Shiro 应用程序 引入依赖: <?xml version="1.0" encoding="UTF-8"?> <p ...

  5. 安卓之各种Adapter优劣分析

    文章摘要 在 Android 开发中,适配器(Adapter)是一种非常重要的设计模式,它用于将数据与视图组件进行绑定.适配器可以帮助我们在不同的视图组件(如 ListView.GridView.Re ...

  6. 万界星空科技电子电器装配行业云MES解决方案

    电子电器装配属于劳动密集型.科技含量较高的行业,产品零部件种类繁多,生产组装困难,生产过程存在盲点,同时也决定了生产流水线多且对自动化水平要求较高. 万界星空科技提供的电子行业解决方案,从仓储管理.生 ...

  7. 学透java自增(++)自减(--)运算符

    基本介绍 自增(++)和自减(--)运算符是对变量在原始值的基础上进行加1或减1的操作. 它们都有前缀和后缀两种形式. 前缀就是++在前面,后缀就是++在后面 前缀先自增(减),后缀后自增(减) 前缀 ...

  8. MinIO客户端之cp

    MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc cp 上传文件至指定桶内,命令如下: ./mc cp ./local.json local1/bkt1/ 控 ...

  9. 构建 dotnet&vue 应用镜像->推送到 Nexus 仓库->部署为 k8s 服务实践

    前言 前面分享了 k8s 的部署安装,本篇来点实操,将会把一个 .net core + vue 的项目(zhontai),打包构建成 docker 镜像,推送到 nexus 镜像仓库,并部署到 k8s ...

  10. 合宙esp32 c3 micro python 固件配置(基于thonny)

    首先,本文档是已经配置过其他esp32后发现合宙的配置需要修改一些地方. 为了让新手们减少掉坑成本,故做了一个图文指导. 准备工作: 1.thonny安装(不讲,自己去查教程) 2.esp32c3 m ...