C. New Skill Acquired
多源bfs
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;int main() {int n;cin >> n;vector<vector<int>> to(n);vector<int> got;rep(i, n) {int a, b;cin >> a >> b;if (a == 0) {got.push_back(i);}else {--a; --b;to[a].push_back(i);to[b].push_back(i);}}vector<bool> used(n);queue<int> q;for (int v : got) {used[v] = true;q.push(v);}while (q.size()) {int v = q.front(); q.pop();for (int u : to[v]) {if (used[u]) continue;used[u] = true;q.push(u);}}int ans = 0;rep(i, n) if (used[i]) ans++;cout << ans << '\n';return 0;
}
D. 2x2 Erasing 2
容易发现答案不超过 \(9\)
那么最多有 \(C(49, 9)\) 种方案,于是直接暴搜即可
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;void solve() {int h, w;cin >> h >> w;vector<string> s(h);rep(i, h) cin >> s[i];int ans = 9;auto f = [&](auto& f, int now) -> void {if (now >= ans) return;rep(i, h-1)rep(j, w-1) {int cnt = 0;rep(di, 2)rep(dj, 2) if (s[i+di][j+dj] == '#') cnt++;if (cnt == 4) {rep(dj, 2) {s[i+1][j+dj] = '.';f(f, now+1);s[i+1][j+dj] = '#';}return;}}ans = min(ans, now);};f(f, 0);cout << ans << '\n';
}int main() {int t;cin >> t;while (t--) solve();return 0;
}
E. Cut in Half
用大根堆来维护二元组 (值,数量)
,批量处理相同长度的木棍的切割操作
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;void solve() {int n, k, x;cin >> n >> k >> x;using P = pair<double, int>;priority_queue<P> q;rep(i, n) {int a;cin >> a;q.emplace(a, 1);}while (k) {auto [l, c] = q.top(); q.pop();if (k < c) {q.emplace(l, c-k);c = k;}k -= c;q.emplace(l/2, c*2);}while (1) {auto [l, c] = q.top(); q.pop();x -= c;if (x <= 0) {printf("%.10f\n", l);return;}}
}int main() {int t;cin >> t;while (t--) solve();return 0;
}
F. Adding Chords
性质:
区间
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/908647.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!相关文章
解决 Windows 无法挂载 HTTP WebDAV(AList,OpenList)的问题
Windows 默认的 WebClient 服务仅支持 HTTPS 协议,而本地搭建的 WebDAV 服务通常基于 HTTP 协议,但是我们有办法将其“修复”。解决 Windows 无法挂载 HTTP WebDAV 的问题
当前市面上大多数网盘都可以挂载到 AList(…
在Ubuntu系统中使用gcc和Makefile编译C程序
一.用Ubuntu系统编写hello world程序并编译运行
1.用vim命令编写hello world程序代码2.用gcc命令编译并运行二.用Ubuntu系统编写主程序文件main1.c和子程序文件sub1.h并编译运行
1.编写子程序sub1.h2.编写主程序main1.…
HN CSP-S 2024 游记
本文中,一 Day 指一段 \(24\) 小时的时间段,从 \(4:00\) 开始计算。S1 Day -1
@湖南省队御用绫厨TM_Sharweek 拉我进了一个群。
熬到了凌晨一点,与 @湖南省队御用绫厨TM_Sharweek 在 QQ 上进行了聊天。
睡着了。
S1…
CSP-S 2025 初赛解析
T1有 5 个红色球和 5 个蓝色球,它们除了颜色之外完全相同。将这 10 个球排成一排,要求任意两个蓝色球都不能相邻,有多少种不同的排列方法? ( )A. 25
B. 30
C. 6
D. 120选 C.
排列组合:不相邻问题先排 \(5\) 个红…
paddleocr 调试
AppData\Local\Programs\Python\Python39\Lib\site-packages\paddleocr
我修改的是这个目录下的源码
testuserjiagou
https://aws.amazon.com/cn/blogs/architecture/disaster-recovery-dr-architecture-on-aws-part-i-strategies-for-recovery-in-the-cloud/
IDEA 自动编译和热部署
测试环境 IDEA2023
一 自动编译菜单 File >> Settings >> Build,Execution,Deployment >> Compiler 勾选上 Build project automatically
二 热加载
1. 设置自动编译后,添加依赖<dependency&g…
testusers3
我们需要为AWS S3创建一个策略,以便允许ALB(Application Load Balancer)将访问日志上传到指定的S3存储桶。
策略需要满足以下条件:
允许ALB服务将日志写入S3存储桶。
只允许对特定存储桶和特定前缀(如果需要)的写…
RabbitMQ核心模型简介,Hello World的生产与消费
本章学习目标理解AMQP模型中的核心概念:Connection, Channel, Producer, Consumer, Queue。创建一个.NET项目并添加RabbitMQ客户端库。使用C#编写代码发送一条消息("Hello World")。使用C#编写代码接收并…
Linux 基础命令 02
一、查看文件内容及内容处理命令
1.1 vi/vim
vi命令 是UNIX操作系统和类UNIX操作系统中最通⽤的全屏幕纯⽂本编辑器。Linux中的vi编辑器叫vim,它是vi的增强版(vi Improved),与vi编辑器完全兼容,⽽且实现了很多增强…
RabbitMQ核心模型简介,Hello World的发送与消费
本文目标理解AMQP模型中的核心概念:Connection, Channel, Producer, Consumer, Queue。创建一个.NET项目并添加RabbitMQ客户端库。使用C#编写代码发送一条消息("Hello World")。使用C#编写代码接收并处理…
Proxy 库解析(三)
ptrs
template <class F>
struct converter {explicit converter(F f) noexcept : f_(std::move(f)) {}converter(const converter&) = delete;template <class T>operator T() && noexcept(s…
软工个人项目 - Helen
论文查重系统设计与实现
GitHub作业链接: https://github.com/Playerhh/playerhh/tree/main/3223004773这个作业属于哪个课程
https://edu.cnblogs.com/campus/gdgy/Class34Grade23ComputerScience/这个作业要求在哪里…
记录 | 心理行动机制模型
你說:
在学校操场跑步,然后拉了十个单杠,想着要不再做个俯卧撑吧,但想着累了,不做了,但又想了想,还不如去想,就算做一个也是做,那还不如做试试,于是一个变成两个,两个变成五个,五个变成十个,十个在上25个…