2024.12.14 周六

news/2025/1/6 7:34:22/文章来源:https://www.cnblogs.com/jkkk/p/18607825

2024.12.14 周六


Q1. 1000

You are given two strings $a$ and $b$ of equal length, consisting of only characters 0 and/or 1; both strings start with character 0 and end with character 1.

You can perform the following operation any number of times (possibly zero):

  • choose one of the strings and two equal characters in it; then turn all characters between them into those characters.

You have to determine if it's possible to make the given strings equal by applying this operation any number of times.

Input

($2 \le |a| \le 5000$), ($2 \le |b| \le 5000$), $|a| = |b|$
both strings start with 0 and end with 1;

Q2. 1000

Pak Chanek is the chief. On one night filled with lights, Pak Chanek has a sudden and important announcement that needs to be notified to all of the $n$ residents.

First, Pak Chanek shares the announcement directly to one or more residents with a cost of $p$ for each person. After that, the residents can share the announcement to other residents . For each $i$, if the $i$-th resident has got the announcement at least once , he/she can share the announcement to at most $a_i$ other residents with a cost of $b_i$ for each share.

If Pak Chanek can also control how the residents share the announcement to other residents, what is the minimum cost for Pak Chanek to notify all $n$ residents of Khuntien about the announcement?

Q3. 1000

Artem suggested a game to the girl Olya. There is a list of $n$ arrays, where the $i$-th array contains $m_i \ge 2$ positive integers $a_{i,1}, a_{i,2}, \ldots, a_{i,m_i}$.

Olya can move at most one (possibly $0$) integer from each array to another array. Note that integers can be moved from one array only once, but integers can be added to one array multiple times, and all the movements are done at the same time.

The beauty of the list of arrays is defined as the sum $\sum_{i=1}^n \min_{j=1}^{m_i} a_{i,j}$. In other words, for each array, we find the minimum value in it and then sum up these values.

The goal of the game is to maximize the beauty of the list of arrays. Help Olya win this challenging game!

Q4. 1000

Alex got a new game called "GCD permutations" as a birthday present. Each round of this game proceeds as follows:

  • First, Alex chooses a permutation$^{\dagger}$ $a_1, a_2, \ldots, a_n$ of integers from $1$ to $n$.
  • Then, for each $i$ from $1$ to $n$, an integer $d_i = \gcd(a_i, a_{(i \bmod n) + 1})$ is calculated.
  • The score of the round is the number of distinct numbers among $d_1, d_2, \ldots, d_n$.

Alex decided to find a permutation $a_1, a_2, \ldots, a_n$ such that its score is as large as possible.

Q5. 1000

Vlad remembered that he had a series of $n$ tiles and a number $k$. The tiles were numbered from left to right, and the $i$-th tile had colour $c_i$.

If you stand on the first tile and start jumping any number of tiles right, you can get a path of length $p$. The length of the path is the number of tiles you stood on.

Vlad wants to see if it is possible to get a path of length $p$ such that:

  • it ends at tile with index $n$;
  • $p$ is divisible by $k$
  • the path is divided into blocks of length exactly $k$ each;
  • tiles in each block have the same colour, the colors in adjacent blocks are not necessarily different.

For example, let $n = 14$, $k = 3$.

The colours of the tiles are contained in the array $c$ = [$\color{red}{1}, \color{violet}{2}, \color{red}{1}, \color{red}{1}, \color{gray}{7}, \color{orange}{5}, \color{green}{3}, \color{green}{3}, \color{red}{1}, \color{green}{3}, \color{blue}{4}, \color{blue}{4}, \color{violet}{2}, \color{blue}{4}$]. Then we can construct a path of length $6$ consisting of $2$ blocks:

$\color{red}{c_1} \rightarrow \color{red}{c_3} \rightarrow \color{red}{c_4} \rightarrow \color{blue}{c_{11}} \rightarrow \color{blue}{c_{12}} \rightarrow \color{blue}{c_{14}}$

All tiles from the $1$-st block will have colour $\color{red}{\textbf{1}}$, from the $2$-nd block will have colour $\color{blue}{\textbf{4}}$.

It is also possible to construct a path of length $9$ in this example, in which all tiles from the $1$-st block will have colour $\color{red}{\textbf{1}}$, from the $2$-nd block will have colour $\color{green}{\textbf{3}}$, and from the $3$-rd block will have colour $\color{blue}{\textbf{4}}$.

------------------------独自思考分割线------------------------

  • Q1Q2是昨天被卡了,这次都换了思路,一发过。还是得思考最原始的方式然后优化,不能只想着观察出答案。剩下3题wa3发1小时多点。

A1.

  1. 昨天读题漏了:0开始1结束。本质就是左右2段向中间最多覆盖各一次且不相交,能否将不同点全部覆盖。
  2. 0/1可覆盖点最多分别n个。n^2种覆盖情况。
  3. 考虑如何快速判断是否全部覆盖:前缀预处理查点数。
  4. 其实这道题观察还真可以解。

A2.

  1. 过程性贪心,每一步需要维护所有可选代价找最优代价。

A3.

  1. 贪心加结论。贪心就是把最小值移到一个数组。枚举所有数组作为这个数组即可。
  2. 答案就是min(a[i][0])+ sum(a[i][1])/次小值的和-a[k][1]。

A4.

  1. 考虑可构造出不同gcd的个数。发现为n/2个。
  2. 同时对于构造x,必须有x的倍数在旁边。
  3. 2 4 8 16 3 6 12 5 10 20 7 14 9 18 11 13 15 17 19 1

A5

  1. 读漏题wa2发:开始结束必须选。
  2. 本质就是根据首尾是否相同分为1/2块,每块是否有 $k$ 个相同的数。

------------------------代码分割线------------------------

A1.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{string a, b;cin >> a >> b;int n = a.size();a = " " + a;b = " " + b;vector<int> l, r, pre(n + 2);for (int i = 1; i <= n; i++){pre[i] = pre[i - 1] + (a[i] != b[i]);if (a[i] == b[i]){if (a[i] == '0')l.push_back(i);elser.push_back(i);}}int f = 0;for (auto l : l)for (auto r : r)if (l < r){if (pre[r - 1] - pre[l] == 0)f = 1;}cout << (f ? "YES" : "NO") << endl;
}

A2.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n, p;cin >> n >> p;struct Node{/* data */int a, b;};vector<Node> vec(n);for (auto &[a, b] : vec)cin >> a;for (auto &[a, b] : vec)cin >> b;sort(vec.begin(), vec.end(), [](Node &a, Node &b){if (a.b == b.b)return a.a > b.a;elsereturn a.b < b.b; });priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;int res = 0;for (int i = 0; i < n; i++){int w = p;if (q.size() && q.top().first < w){auto [w1, cnt] = q.top();q.pop();w = w1;if (cnt > 1)q.push({w1, cnt - 1});}res += w;q.push({vec[i].b, vec[i].a});}cout<< res << endl;
}
// 未讨论p,bi大小,仅遍历贪心不够优
// void _()
// {
//     int n, p;
//     cin >> n >> p;
//     struct Node
//     {
//         /* data */
//         int a, b;
//     };
//     vector<Node> vec(n);
//     for (auto &[a, b] : vec)
//         cin >> a;
//     for (auto &[a, b] : vec)
//         cin >> b;
//     vector<int> pre(n + 1);
//     sort(vec.begin(), vec.end(), [](Node &a, Node &b)
//          {
//         if (a.b == b.b)
//             return a.a > b.a;
//         else
//             return a.b < b.b; });
//     for (int i = 0; i < n; i++)
//         pre[i + 1] = pre[i] + vec[i].a;
//     int res = 0;
//     for (int i = 1; i <= n; i++)
//     {
//         res += vec[i - 1].a * vec[i - 1].b;
//         if (i + pre[i] >= n)
//         {
//             res += i * p;
//             res -= (i + pre[i] - n) * vec[i - 1].b;
//             break;
//         }
//     }
//     res = min(res, n * p);
//     cout
//         << res << endl;
// }

A3.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<vector<int>> a(n);for (int i = 0; i < n; i++){int m;cin >> m;while (m--){int x;cin >> x;a[i].push_back(x);}sort(a[i].begin(), a[i].end());}int sum2 = 0, min1 = 1e9;for (auto a : a)sum2 += a[1], min1 = min(min1, a[0]);int res = 0;for (int i = 0; i < n; i++){int t = sum2 - a[i][1] + min1;res = max(res, t);}cout << res << endl;
}

A4.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<int> vis(n + 1);for (int i = 2; i <= n; i++)for (int j = 0; i * (1ll << j) <= n; j++)if (!vis[i * (1ll << j)]){cout << i * (1ll << j) << ' ';vis[i * (1ll << j)] = 1;}cout << 1 << ' ' << endl;
}

A5.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n, k;cin >> n >> k;int cnt = 0;map<int, int> has;map<int, int> res;vector<int> a(n + 1);for (int i = 1; i <= n; i++)cin >> a[i];int f = 0, f1 = 0;for (int i = 1; i <= n; i++){int x = a[i];has[x]++;if (!f1){if (has[a[1]] == k){f1 = 1;has.clear();}}else if (has[a[n]] == k)f = 1;}if (a[1] == a[n] && f1)f = 1;cout << (f ? "YES" : "NO") << endl;
}

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

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

相关文章

#oscp#渗透测试 kioptix level 3靶机getshell及提权教程

声明! 文章所提到的网站以及内容,只做学习交流,其他均与本人以及泷羽sec团队无关,切勿触碰法律底线,否则后果自负!!!!一、靶机搭建 点击扫描虚拟机选择靶机使在文件夹即可二、信息收集 前言 信息收集阶段,因为这里是靶机,所以不需要做什么,但是实际渗透测试中,大家…

rust学习十四.2、工作空间(workspace)

和大部分语言一样,cargo也可以创建一个工作空间,以便可以包含多个二进制单元和库单元,从而构建较为复杂的工程。 构建这样一个空间空间主要依赖两个手段:Cargo.toml和单元之间的目录结构 从效果上看,rust的Cargo在工作空间上的管理和maven大体相似,但是还不如maven那么的…

08一些元素的使用

一、今日学习内容 1、HTML常见的元素 HTML结构分析,H1到6,p元素,img,a元素,div,span元素 不常用元素,HTML全局属性 2、额外知识点补充 字符实体,URL地址,元素语义化,SEO优化,字符编码tip:这样在编写代码的时候就不用频繁的切换到英文状态下了 这样会提高编写代码的…

零基础科研小白の服务器看这个就够了

服务器 我们上网的时候经常会遇到连不上服务器,那啥是服务器呢。 其实就是一些特化的计算机,是远处有物理实体的设备。 from 挑战全网最硬核服务器基础知识 什么是服务器? 有 高计算 能力,能够通过网络 提供多种服务 的计算机。 服务器啥模样?服务器有什么特点? 计算能力…

2024-2025-1 20241415 《计算机基础与程序设计》第十二周学习总结

2024-2025-1 20241415《计算机基础与程序设计》第十二周学习总结 作业信息这个作业属于哪个课程 2024-2025-1-计算机基础与程序设计这个作业要求在哪里 2024-2025-1计算机基础与程序设计第十二周作业这个作业的目标 复习巩固前面所学的内容作业正文 https://www.cnblogs.com/zh…

Python序列的应用(九):集合以及列表、元组、字典和集合的区别

前言: 一、集合 Python 中的集合同数学中的集合概念类似,也是用于保存不重复元素的。它有可变集合(set)和不可变集合(fozenset)两种。本节所要介绍的可变集合是无序可变序列,而不可变集合在本书中不做介绍。在形式上,集合的所有元素都放在一对{}中,两个相邻元素间使用,分…

jQuery鼠标拖动旋转DOM元素插件

Propeller.js是一款jQuery鼠标拖动旋转DOM元素插件。通过该插件,可以使用鼠标拖动旋转页面中的任意DOM元素。使用方法 通过npm安装插件。npm install Propeller HTML结构 例如要拖动旋转一张图片。<img src="demo.jpg" id="img"> 初始化插件 作为jq…

js消息通知框、对话框、确认框和Loading插件

Notiflix是一款js消息通知框、对话框、确认框和Loading插件。Notiflix通过简单的设置,就可生成非常漂亮的s消息通知框、对话框、确认框和Loading效果。在线预览 下载使用方法 在页面中引入下面的文件。<link rel="stylesheet" href="css/notiflix-1.3.0.mi…

人工智能大语言模型起源篇,低秩微调(LoRA)

上一篇: 《规模法则(Scaling Law)与参数效率的提高》 序言:您在找工作时会不会经常听到LoRA微调,这项技术的来源就是这里了。 (12)Hu、Shen、Wallis、Allen-Zhu、Li、L Wang、S Wang 和 Chen 于2021年发表的《LoRA: Low-Rank Adaptation of Large Language Models》,htt…

群晖Lets Encrypt证书申请

注意本文时效性:2024.9.23 引言 为了保证SSL证书的权威性和安全性,Lets Encrypt 会验证您对域名的控制权。 申请 Lets Encrypt 证书有以下的验证控制权的方式:Web验证:通过在http的有权威的目录下创建一个验证文件以验证对服务器的控制权 Dns验证:通过在 DNS Record 中添加…

《计算机基础与程序设计》第十二周学习总结

学期(如2024-2025-1) 学号(如:20241300) 《计算机基础与程序设计》第十二周学习总结 作业信息这个作业属于哪个课程 <班级的链接> 2024-2025-1-计算机基础与程序设计这个作业要求在哪里 <作业要求的链接> 2024-2025-1计算机基础与程序设计第十二周作业)这个作…

读数据保护:工作负载的可恢复性14备份和恢复数据库

备份和恢复数据库1. 给采用传统方式交付的数据库制作备份 1.1. 某个数据库是新还是旧,跟该数据库是不是传统数据库没有必然的联系,真正的决定因素在于,这个数据库是不是运行在你所管理的服务器或虚拟机里1.1.1. 如果是,那就可以归入按照传统模型来交付的数据库1.1.2. 如果不…