题目区分度不错,不过两题手快铜确实没想到。
Attention is all you need!

H - What is all you need?

签到题

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 1000010, M = N * 2, mod = 998244353, P = 131;
string s;
void solve()
{cin >> s;string u = s.substr(s.size() - 12);if (u == "isallyouneed"){cout << "Yes\n";cout << s.substr(0, s.size() - 12) << "\n";}elsecout << "No\n";
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;// cin >> t;while (t--)solve();return 0;
}
M - 第九届河北省大学生程序设计竞赛

dfs搜索即可。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 1000010, M = N * 2, mod = 998244353, P = 131;
int n, m, ra, rb, rc, pa, pb, pc, f;
vector<int> q;
string s[210];void dfs(int u)
{if (f)return;if (u == n){if (q.size() >= 10 && q.size() <= 13){vector<int> su;for (int i = 1; i <= m; i++){int sum = 0;for (int j = 0; j < q.size(); j++)if (s[i][q[j]] == '1')sum++;su.push_back(sum);}sort(su.begin(), su.end(), greater());if (su[ra - 1] == pa && su[rb - 1] == pb && su[rc - 1] == pc){f = 1;cout << q.size() << "\n";for (int i = 0; i < q.size(); i++)cout << q[i] + 1 << " ";}}return;}dfs(u + 1);q.push_back(u);dfs(u + 1);q.pop_back();
}
void solve()
{cin >> n >> m;for (int i = 1; i <= m; i++)cin >> s[i];cin >> ra >> rb >> rc >> pa >> pb >> pc;dfs(0);if (!f)cout << "-1";
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;// cin >> t;while (t--)solve();return 0;
}
J - Generate 01 String

模拟。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 1000010, M = N * 2, mod = 998244353, P = 131;
int sa, sb;
string s;
void solve()
{cin >> s;for (int i = 0; i < s.size(); i++)if (s[i] == '0')sa++;elsesb++;if (sa != sb){cout << "-1\n";return;}vector<PII> res;priority_queue<PII, vector<PII>, greater<PII>> h;h.push({0, 3});int op = 1;for (int i = 0; i < s.size(); i++){int u = s[i] - '0';if (h.top().y == u)h.pop();else{if (h.top().y == 3){auto t = h.top();h.pop();if (h.size() && h.top().y == u){h.pop();op++;}else{if (u == 0){res.push_back({op, 1});h.push({t.x, 3});h.push({t.x - 1, 1});h.push({t.x - 2, 3});}else{res.push_back({op, 2});h.push({t.x, 3});h.push({t.x - 1, 0});h.push({t.x - 2, 3});}}}else{cout << "-1\n";return;}}}cout << res.size() << "\n";for (int i = 0; i < res.size(); i++)cout << res[i].x << " " << res[i].y << "\n";
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;// cin >> t;while (t--)solve();return 0;
}
K - UNO!

还是模拟,可以用链表,图省事可以用数组模拟链表。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 1000010, M = N * 2, mod = 998244353, P = 131;
string s;
void solve()
{int n, m;cin >> n >> m;vector<int> a(n);for (int i = 0; i < n; i++){cin >> a[i];}vector<int> next(n);iota(next.begin(), next.end(), 1);next[n - 1] = 0;vector<int> pre(n);iota(pre.begin(), pre.end(), -1);pre[0] = n - 1;string op;cin >> op;int cur = 0, v = 1;for (int i = 0; i < m; ++i){if (op[i] == 'C'){a[cur]--;if (a[cur] == 0){pre[next[cur]] = pre[cur];next[pre[cur]] = next[cur];}if (v){cur = next[cur];}else{cur = pre[cur];}}else if (op[i] == 'S'){a[cur]--;if (a[cur] == 0){pre[next[cur]] = pre[cur];next[pre[cur]] = next[cur];}if (v){cur = next[next[cur]];}else{cur = pre[pre[cur]];}}else if (op[i] == 'R'){a[cur]--;if (a[cur] == 0){pre[next[cur]] = pre[cur];next[pre[cur]] = next[cur];}if (v == 1){v = 0;cur = pre[cur];}else{v = 1;cur = next[cur];}}else if (op[i] == 'D'){a[cur]--;if (a[cur] == 0){pre[next[cur]] = pre[cur];next[pre[cur]] = next[cur];}if (v){cur = next[cur];a[cur] += 2;cur = next[cur];}else{cur = pre[cur];a[cur] += 2;cur = pre[cur];}}}for (int i = 0; i < n; ++i){cout << a[i] << '\n';}
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;// cin >> t;while (t--)solve();return 0;
}
A - 棋盘

分类讨论,好像分太多了。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 1000010, M = N * 2, mod = 998244353, P = 131;
string s;
void solve()
{int n;cin >> n;vector<int> a(n), b(n);int alla = 0;int allb = 0;for (int i = 0; i < n; ++i){cin >> a[i];alla += a[i];}for (int i = 0; i < n; ++i){cin >> b[i];allb += b[i];}vector<int> prefix(n), suffix(n);for (int i = 0; i < n; ++i){if (i == 0)prefix[i] = a[0] + b[0];else{prefix[i] = prefix[i - 1] + a[i] + b[i];}}for (int i = n - 1; i >= 0; --i){if (i == n - 1)suffix[i] = a[i] + b[i];else{suffix[i] = suffix[i + 1] + a[i] + b[i];}}// 3// 1// 3// 2// 3// 1 2 3// 3 2 1// 10// 3 2 1 3 3 2 3 9 4 2// 1 3 1 1 4 3 9 3 4 1int all = alla + allb;int l, r;for (int i = 0; i < n; ++i){if (prefix[i] * 2 > all){l = i;break;}}for (int i = n - 1; i >= 0; --i){if (suffix[i] * 2 > all){r = i;break;}}int disl = l, disr = n - r - 1;// cout << disl << ' ' << disr << endl;if (l == r){if (disl == disr){if (alla > allb){cout << "Mandy\n";}else if (alla == allb){cout << "draw\n";}else{cout << "brz\n";}}else if (disl < disr){cout << "Mandy\n";}else{if (disl - 1 == disr){if (alla > allb){cout << "Mandy\n";}else if (alla == allb || prefix[l - 1] * 2 == all){cout << "draw\n";}else{cout << "brz\n";}}else{cout << "brz\n";}}}else{if (disl == disr){if (alla > allb){cout << "Mandy\n";}else if (alla == allb || prefix[l - 1] * 2 == all){cout << "draw\n";}else{cout << "brz\n";}}else if (disl < disr){if (disl + 1 == disr){if (alla > allb){cout << "Mandy\n";}else if (alla == allb || prefix[l - 1] * 2 == all){cout << "draw\n";}else{cout << "brz\n";}}else{cout << "Mandy\n";}}else{if (disl == disr + 1 || disl == disr + 2){if (allb > alla){cout << "brz\n";}else if (alla == allb || suffix[r + 1] * 2 == all){cout << "draw\n";}else{cout << "Mandy\n";}}else{cout << "brz\n";}}}
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;cin >> t;while (t--)solve();return 0;
}
D - 金麦园

这道题比较有意思,首先简化题意,让你求第K大,你会求嘛?
对的,二分就可以了。现在让我们求前K个的和呢?
其实一样的,先排序求出第K大,再计算每个相邻差值的贡献,用到了双指针,二分+二分会TLE,所以优化成双指针。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 1000010, M = N * 2, mod = 998244353, P = 131;
int n, k;
int a[N], s[N], mp[N];int check(int x)
{int sum = 0;for (int i = 1, j = 1; i <= n; i++){while (j + 1 <= n && a[j + 1] - a[i] < x)j++;sum += j - i;}return sum;
}
void solve()
{cin >> n >> k;for (int i = 1; i <= n; i++)cin >> a[i];sort(a + 1, a + n + 1);int l = 0, r = 1e9;while (l < r){int mid = (l + r + 1) / 2;if (check(mid) < k)l = mid;elser = mid - 1;}int cnt = 0, res = 0;for (int i = 1, j = 1; i <= n; i++){while (j + 1 <= n && a[j + 1] - a[i] < l)j++;cnt += j - i;// cout << i << " " << j << "\n";mp[i + 1] = j - i;s[i + 1]++, s[j + 1]--;}for (int i = 1; i <= n; i++)s[i] += s[i - 1];for (int i = 2; i <= n; i++){if (mp[i]){res += mp[i] * (a[i] - a[i - 1]);if (mp[i] - s[i]){mp[i + 1] += mp[i] - s[i];}}}if (cnt < k)res += (k - cnt) * l;cout << res << "\n";
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;// cin >> t;while (t--)solve();return 0;
}
I - 感染

换根DP。

#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
#define double long doubleusing namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
// const int N = 1000010, M = N * 2, mod = 998244353, P = 131;void solve()
{int n;cin >> n;vector<vector<int>> adj(n);vector<int> d(n);for (int i = 1; i < n; i++){int u, v;cin >> u >> v;u--;v--;adj[u].push_back(v);adj[v].push_back(u);d[u]++;d[v]++;}vector<int> sumd(n), dep(n);// int maxdep = 0;auto dfs = [&](auto &&self, int x, int p = -1) -> void{sumd[x] = d[x];for (auto y : adj[x]){if (y == p){continue;}dep[y] = dep[x] + 1;// maxdep = max(maxdep, dep[y]);self(self, y, x);sumd[x] += sumd[y];}};// int m = maxdep + 1;dfs(dfs, 0);vector<int> dp(n);dp[0] = 1;for (int i = 0; i < n; i++){dp[0] += d[i] * (n + 1 - dep[i]);}// cout << sumd[0] << "\n";auto dfs2 = [&](auto &&self, int x, int p = -1) -> void{for (auto y : adj[x]){if (y == p){continue;}dp[y] = dp[x] + 2 * sumd[y] - sumd[0];// cout << "!!!\n";// cout << "sumd " << sumd[y] << "\n";// cout << y << " " << dp[y] << "\n";self(self, y, x);}};dfs2(dfs2, 0);// for (int i = 0; i < n; i++)// {//     cout << dp[i] << "\n";// }int maxv = *std::max_element(dp.begin(), dp.end());vector<int> vec;for (int i = 0; i < n; i++){if (dp[i] == maxv){vec.push_back(i + 1);}}cout << vec.size() << "\n";for (auto x : vec){cout << x << " \n"[x == vec.back()];}
}signed main()
{std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int t = 1;cin >> t;while (t--)solve();return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/82464.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/82464.shtml
英文地址,请注明出处:http://en.pswp.cn/pingmian/82464.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【IOS】【OC】【应用内打印功能的实现】如何在APP内实现打印功能,连接本地打印机,把想要打印的界面打印成图片

【IOS】【OC】【应用内打印功能的实现】如何在APP内实现打印功能&#xff0c;连接本地打印机&#xff0c;打印想打印的界面 设备/引擎&#xff1a;Mac&#xff08;14.1.1&#xff09;/cocos 开发工具&#xff1a;Xcode 开发语言&#xff1a;OC/C 开发需求&#xff1a;工程中…

AWS WebRTC:获取信令服务节点和ICE服务节点

建立WebRTC的第一步是获取信令服务节点和ICE服务节点。 前提条件是有访问AWS的密钥&#xff0c;主要是ak&#xff0c;sk&#xff0c;token&#xff0c;我这边是业务云有接口可以返回这些信息&#xff0c;所以我直接从业务云获取。 先介绍一下什么是ak&#xff0c;sk&#xff…

C++23 新成员函数与字符串类型的改动

文章目录 引言std::basic_string::contains 与 std::basic_string_view::contains (P1679R3)功能介绍示例代码优势 禁止从 nullptr 构造 std::basic_string 和 std::basic_string_view (P2166R1)背景改动影响 std::basic_string_view 的显式范围构造函数 (P1989R2)功能介绍示例…

VMware-MySQL主从

MySQL主从 服务器信息 服务器类型角色主机地址主机名称虚拟机master192.168.40.128test-1虚拟机slave192.168.40.129test-2 Master 配置&#xff08;192.168.40.128&#xff09; 删除自动生成的配置 /var/lib/mysql/auto.cnf [roottest-1 ~]# rm -rf /var/lib/mysql/auto.…

Java组合、聚合与关联:核心区别解析

在Java中&#xff0c;组合、聚合和关联是描述类之间关系的三种不同方式&#xff0c;它们的核心区别在于对象间的依赖强度和生命周期管理。以下是它们的详细对比&#xff1a; 1. 关联&#xff08;Association&#xff09; 定义&#xff1a;最基本的类间关系&#xff0c;表示一个…

如何保护网络免受零日漏洞攻击?

零日漏洞&#xff08;Zero-Day Vulnerability&#xff09;是指软件或系统中尚未被厂商发现或修补的安全漏洞。这个名称中的“零日”意味着&#xff0c;从漏洞被发现到厂商发布修复补丁的时间是零天&#xff0c;也就是说&#xff0c;黑客可以利用这个漏洞进行攻击&#xff0c;而…

linux快速入门-VMware安装linux,配置静态ip,使用服务器连接工具连接,快照和克隆以及修改相关配置信息

安装VMWare 省略&#xff0c;自己检索 安装操作系统-linux 注意&#xff1a;需要修改的我会给出标题&#xff0c;不要修改的直接点击下一步就可以 选择自定义配置 选择稍后安装操作系统 选择合适的内存 选择NAT模式 仅主机模式 虚拟机只能和主机通信&#xff0c;不能上网…

Nest全栈到失业(一):Nest基础知识扫盲

Nest 是什么? 问你一个问题,node是不是把js拉出来浏览器环境运行了?当然,他使用了v8引擎加上自己的底层模块从而实现了,在外部编辑处理文件等;然后它使用很多方式来发送请求是吧,你知道的什么http.request 或 https.request; 我们浏览器中,使用AJAX以及封装AJAX和http的Axios…

Streamlit 项目知识点总结

目录 1. 单选框、下拉框格式化 2. 多媒体资源的引用 2.1 搭建一个简易的http服务器 2.2 约定多媒体资源的输入格式 2.3 解析多媒体资源 3. 设置页面的全局背景图片 4. 输出流式文本&#xff08;类似打字效果&#xff09; 4.1 使用内置的 st.write_stream 方法实现 4.2…

maven模块化开发

使用方法 将项目安装到本地仓库 mvn install 的作用 运行 mvn install 时&#xff0c;Maven 会执行项目的整个构建生命周期&#xff08;包括 compile、test、package 等阶段&#xff09;&#xff0c;最终将构建的 artifact 安装到本地仓库&#xff08;默认路径为 ~/.m2/repos…

(11)Service Mesh架构下Java应用实现零信任安全模型

Service Mesh架构下Java应用实现零信任安全模型 📌 TL;DR: 本文详细介绍如何在Service Mesh架构中实现零信任安全模型,包括身份认证、授权控制、加密通信和持续监控四大核心技术,以及与Istio、Envoy等组件的集成方案。 目录 零信任安全模型概述关键技术实现最佳实践Service…

修改 K8S Service 资源类型 NodePort 的端口范围

在 Kubernetes 中&#xff0c;Service 类型为 NodePort 时&#xff0c;默认分配的端口范围为 30000~32767。如果你希望使用自定义端口&#xff08;如 8080、8888 等&#xff09;&#xff0c;就需要修改 kube-apiserver 的默认配置。 本文将详细介绍如何修改 Kubernetes 中 Nod…

MySQL 可观测性最佳实践

MySQL 简介 MySQL 是一个广泛使用的开源关系型数据库管理系统&#xff08;RDBMS&#xff09;&#xff0c;以其高性能、可靠性和易用性而闻名&#xff0c;适用于各种规模的应用&#xff0c;从小型网站到大型企业级系统。 监控 MySQL 指标是维护数据库健康、优化性能和确保数据…

CentOS安装最新Elasticsearch8支持向量数据库

大家都知道Elasticsearch是支持向量的存储和查询的&#xff0c;今天我们来介绍下如何安装支持向量数据库的Elasticsearch &#xff0c; 操作环境是CentOS。 成功安装截图 大家进入系统shell&#xff0c;跟我执行下面命令进行安装。 更新系统 [rootlocalhost ~]# sudo yum u…

SDL2常用函数SDL事件处理:SDL_Event|SDL_PollEvent

SDL_Event SDL_Event是个联合体&#xff0c;是SDL中所有事件处理的核心。 SDL_Event是SDL中使用的所有事件结构的并集。 只要知道了那个事件类型对应SDL_Event结构的那个成员&#xff0c;使用它是一个简单的事情。 下表罗列了所有SDL_Event的所有成员和对应类型。 Uint32typ…

webpack吐环境分析

需要解决的问题 扣取下来的webpack文件过大 解决思路 用ast将需要的代码扣下来 结果展示 实现步骤 第一步&#xff1a;我们得知道需要哪些模块 在入口处&#xff0c;增加模块记录 第二步&#xff0c;分析ast代码 通过分析发现,key 有三种值 分别为NumbericLiteral、StringLi…

微软语音合成助手资源下载

微软语音合成助手资源下载 【下载地址】微软语音合成助手资源下载 微软语音合成助手是一款基于先进AI技术的文本转语音工具&#xff0c;能够将文字内容快速转换为自然流畅的语音。它支持高度自定义的语音参数&#xff0c;包括语速、音调、发音和停顿等&#xff0c;满足多样化需…

青少年编程与数学 02-020 C#程序设计基础 01课题、C#编程概要

青少年编程与数学 02-020 C#程序设计基础 01课题、C#编程概要 一、微软.NET开发平台1. 核心组件2. 特点3. 应用场景4. 开源与社区5. 版本与更新6. 学习资源 二、C# 编程语言1. 历史背景2. 语言特性&#xff08;1&#xff09;面向对象&#xff08;2&#xff09;类型安全&#xf…

图片文件未正确加载​—— Webpack 无法正确解析图片,生成了一个空的 Base64 URL

如果你打印出的图片 URL 是 data:image/png;base64, 后面没有实际的 Base64 数据&#xff0c;可能有以下几种原因&#xff1a; ​​1. 图片文件未正确加载​​ ​​可能原因​​&#xff1a;图片路径错误&#xff0c;导致 Webpack 无法正确解析图片&#xff0c;生成了一个空的…

3D打印仿造+ AI大脑赋能,造出会思考的全景相机

在自然界的生存竞赛里&#xff0c;节肢动物堪称视觉界的 "卷王"&#xff01;那些长着复眼的小机灵鬼&#xff0c;比如蜜蜂、蜻蜓&#xff0c;别看个头小&#xff0c;视觉能力却超强。 现在&#xff0c;科学家把它们的眼睛 " 偷"过来啦 —— 不是真偷&…