2024.12.23 周一

news/2024/12/24 9:51:01/文章来源:https://www.cnblogs.com/jkkk/p/18626682

2024.12.23 周一


Q1. 1100

Alice and Bob are playing a game. They have an array $a_1, a_2,\ldots,a_n$. The game consists of two steps:

  • First, Alice will remove at most $k$ elements from the array.
  • Second, Bob will multiply at most $x$ elements of the array by $-1$.

Alice wants to maximize the sum of elements of the array while Bob wants to minimize it. Find the sum of elements of the array after the game if both players play optimally.


Q2. 1100

You are given a string $s$ of length $n$. Let's define two operations you can apply on the string:

  • remove the first character of the string;
  • remove the second character of the string.

Your task is to find the number of distinct non-empty strings that can be generated by applying the given operations on the initial string any number of times (possibly zero), in any order.


Q3. 1100

Monocarp is playing a computer game. In order to level up his character, he can complete quests. There are $n$ quests in the game, numbered from $1$ to $n$.

Monocarp can complete quests according to the following rules:

  • the $1$-st quest is always available for completion;
  • the $i$-th quest is available for completion if all quests $j < i$ have been completed at least once.

Note that Monocarp can complete the same quest multiple times.

For each completion, the character gets some amount of experience points:

  • for the first completion of the $i$-th quest, he gets $a_i$ experience points;
  • for each subsequent completion of the $i$-th quest, he gets $b_i$ experience points.

Monocarp is a very busy person, so he has free time to complete no more than $k$ quests. Your task is to calculate the maximum possible total experience Monocarp can get if he can complete no more than $k$ quests.


Q4. 1100

You are given a tree$^{\dagger}$. In one zelda-operation you can do follows:

  • Choose two vertices of the tree $u$ and $v$;
  • Compress all the vertices on the path from $u$ to $v$ into one vertex. In other words, all the vertices on path from $u$ to $v$ will be erased from the tree, a new vertex $w$ will be created. Then every vertex $s$ that had an edge to some vertex on the path from $u$ to $v$ will have an edge to the vertex $w$.

Illustration of a zelda-operation performed for vertices $1$ and $5$.

Determine the minimum number of zelda-operations required for the tree to have only one vertex.

$^{\dagger}$A tree is a connected acyclic undirected graph.


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

  • 用时:32 8 8 40(-1)。1、2、4有意思。1、3用到了遍历维护思想,可找 $n$ 种方案的最优解。4观察结论还是从小数据更易发现思路,树还是定根更好看。

A1.

  1. 一开始没思考本质出了个假思路:删除最大的min(k,x)个元素。
  2. It is optimal for Bob to negate the $x$ largest elements of the array. So in order to minimize the damage Bob will do, Alice should always remove some number of largest elements.
  3. To solve the problem, we can sort the array and iterate over $i$ ($0 \leq i \leq k$) where $i$ is the number of elements Alice removes. For each $i$, we know that Alice will remove the $i$ largest elements of the array and Bob will then negate the $x$ largest remaining elements.
  4. 前缀和/扫过去变量维护(细节处理)。

A2.

  1. 考虑长度 $1$ ~ $n$ 的字符串数,由于只能删除第一个/第二个字母,最后的字符串的后 $len-1$个字母一定是源字符串的后缀。
  2. 结论:不同字符数的前缀和之和。

A3.

  1. 一眼。后面由前面限制,遍历维护求最大值。
  2. So the answer to the problem is the maximum of $\sum\limits_{j=1}^{i} a_j + \max\limits_{j=1}^{i} b_j \cdot (k - i)$ over all values of $i$ from $1$ to $\min(n, k)$. Note that the value of $n$ is too large to calculate sums and maximums in the aforementioned formula every time (for each $i$ independently), so you have to maintain these values as the value for $i$ grows.

A4.

  1. 出了假思路:每次操作减少一片叶子-> $1片/2片$。
  2. 结论观察。在有根树的视图更易找结论,或从点少的树开始找最优结论:前 $n-1$ 次每次可减少2片叶子。
    We can prove by induction that on any tree with $K$ leaves, the answer is $[{\frac{K + 1}{2}}]$, where with $[x]$ we denote the greatest integer smaller than $x$. This can be proven by induction, we will give an overview of what a proof would look like:
  • For two leaves, the answer is clearly $1$.
  • For three leaves, the answer is clearly $2$.
  • For more than four leaves, it is always the case that we can find two leaves for which the node that will be created as a result of applying an operation on these two will have degree greater than $1$ (i.e. it will not be a leaf)

The third argument holds because in a tree with four leaves, we have either at least two nodes with degree at least $3$ (and as such we can choose two leaves which contain these two nodes on their chain), or a node with degree at least $4$. Furthermore, it reduces the number of leaves in the tree by $2$.

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

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 _()
{int n, k, x;cin >> n >> k >> x;vector<int> a(n + 1);for (int i = 1; i <= n; i++)cin >> a[i];sort(a.begin() + 1, a.end());int un_neg = 0, neg = 0;for (int i = 1; i <= n - x; i++)un_neg += a[i];for (int i = n - x + 1; i <= n; i++)neg += -a[i];int res = un_neg + neg;int st = n - x, ed = n;int cnt = 0;while (ed >= 0 && ++cnt <= k){un_neg -= a[st];neg += -a[st] + a[ed];res = max(res, un_neg + neg);// bug3(st, un_neg, neg);st--, ed--;st = max(0ll, st);}cout << res << endl;//  假思路// int move = min(x, k);// int mul = max(0ll, x - k);// int res = 0;// for (int i = move; i < n; i++)//     res += i - move < mul ? -a[i] : a[i];// cout << res << 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;cin >> n;string s;cin >> s;map<char, int> cnt;int res = 0;for (auto v : s){cnt[v]++;res += cnt.size();}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, k;cin >> n >> k;vector<int> a(n + 1), b(n + 1);for (int i = 1; i <= n; i++)cin >> a[i];for (int i = 1; i <= n; i++)cin >> b[i];int maxb = b[1], pre = a[1];int res = pre + (k - 1) * maxb;for (int i = 2; i <= n && i <= k; i++){pre += a[i];maxb = max(maxb, b[i]);int ans = pre + max(0ll, k - i) * maxb;res = max(res, ans);}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> d(n + 1);vector<vector<int>> e(n + 1);for (int i = 1; i < n; i++){int u, v;cin >> u >> v;e[u].push_back(v);e[v].push_back(u);d[u]++, d[v]++;}int leaf = 0;for (int i = 1; i <= n; i++)leaf += d[i] == 1;cout << (leaf + 1 >> 1) << endl;// int leaf = 0, special_leaf = 0;// for (int i = 1; i <= n; i++)// {//     if (d[i] == 1)//     {//         int p = e[i][0];//         // bug2(i, e[i][0]);//         if (d[p] > 2)//             special_leaf++;//         else//             leaf++;//     }// }// if (leaf < 2)// {//     int d = 2 - leaf;//     leaf += d;//     special_leaf -= d;// }// // bug2(leaf, special_leaf);// int res = (special_leaf + 1 >> 1) + leaf - 1;// cout << res << endl;
}

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

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

相关文章

yum源一键安装脚本

一、本地yum源镜像挂载到本地mkdir /mnt/cdrom mount /dev/sr0 /mnt/cdrom/ [root@test yum.repos.d]# df -h ...... /dev/sr0 4.4G 4.4G 0 100% /mnt/centos7将原有源进行备份(处理方式自行决定)cd /etc/yum.repos.d && mkdir bak && …

创建响应式数据

创建响应式数据 Vue2中 ​ 在vue2中数据写在对应的data中就是响应式的。 Vue3 ref :可以定义基本类型的响应式数据 先要导入对应的ref,然后才能使用 import {ref} from vue​ 作用:定义响应式变量。 ​ 语法:let xxx = ref(初始值)。 ​ 返回值:一个RefImpl的实例对象…

【深度剖析】自主可控的全国产方案,基于龙芯LS2K1000LA-i!

龙芯LS2K1000LA-i产品简介 LS2K1000LA-i是龙芯双核LoongArch LA264自主架构处理器。创龙科技基于LS2K1000LA-i设计的工业核心板(SOM-TL2K1000)板载的CPU、ROM、RAM、电源、晶振、连接器等所有元器件均采用国产工业级方案,国产化率100%。 此外,创龙科技基于LS2K1000LA-i设计的…

协作文档让销售工作事半功倍的秘密

在现代医疗销售行业中,高效协同是成功的关键。无论是销售方案的制定,客户拜访记录的共享,还是跨部门的合作,在线协作文档正在成为推动团队效率和精准度的核心工具。特别是在医疗销售这种信息密集型领域,在线协作文档不仅改变了团队的沟通方式,更重塑了销售流程,助力企业…

这款跨网文件安全交换系统 凭什么受到各行业的欢迎?

跨隔离网的文件传输交换,这是各个行业都会面临的场景,能解决传输问题的工具也不少,可为什么说有一款跨网文件安全交换系统,在各行业中应用都很广泛,受到各行业的欢迎呢?首先我们来看看跨网文件传输有哪些需求。一、跨网文件传输的普遍需求 跨网文件传输的普遍需求与挑战可…

模型上下文协议MCP

MCP(Model Context Protocol) Anthropic推出的一种开放协议,旨在统一LLM应用于外部数据源之间的通讯协议使之无缝集成,MCP提供了标准化协议使得LLM与所需要的上下文无缝衔接。使用MCP可以插件式为LLM的集成各种外部数据源。MCP概念上图为MCP官方所描述的MCP架构图,MCP Hosts…

TB级大文件如何安全又轻松地发送?FMail文件邮能实现

许多行业的企业存在着发送GB级、TB级大文件的业务场景,如半导体企业、汽车制造企业、跨境电商、地图测绘、生物科研等,都涉及大量大文件的内部及内外部流转需求。 在进行大文件传输时,企业常用的方式主要包括传统邮件、移动U盘拷贝、FTP传输,以及硬盘刻录通过车辆物理运输等…

客户不回消息?试试这些超实用沟通技巧

在销售与客户沟通过程中,我们时常会面临客户未回复消息的情境,这时应该如何妥善处理呢?以下提供了一些实用的沟通话术,旨在帮助你在各种情境下都能更有效地与客户取得联系。 初次接触后客户未回应 客户或许对初次接收的信息不感兴趣,又或是信息众多而被忽略。 推荐话术:“…

Spring事务管理深度解析-从实践到原理

事务管理在系统开发中是不可缺少的一部分,Spring提供了很好事务管理机制 分类 主要分为编程式事务和声明式事务两种。 编程式事务 是指在代码中手动的管理事务的提交、回滚等操作,代码侵入性比较强,如下示例: try {//TODO somethingtransactionManager.commit(status); } c…

创建用于预测序列的人工智能模型,设计模型架构。

上一篇:《创建用于预测序列的人工智能模型,设计数据集》 序言:在前一篇中,我们创建了用于训练人工智能模型的数据集。接下来,就要设计模型的架构了。其实,人工智能模型的开发关键并不在于代码量,而在于其中的数学原理和数据集(即人类经验)的深度与质量。 创建模型的架…

原来Flutter背后的布局原理是这样的

文章首发博客网站,由于格式解析问题,你可以前往阅读原文如果你是一名web开发者应该对于元素的布局不陌生,直接给目标元素定义尺寸就可以了,如css的width/height 、android的layout_width等等,但在flutter中同样的尺寸定义可能并不会呈现出自己想要的效果 扫码关注公众号,…