首页 > 其他分享 >2024.12.23 周一

2024.12.23 周一

时间:2024-12-26 10:28:07浏览次数:10  
标签:2024.12 elements leaf 23 int two will 周一 define

2024.12.23 周一


Q1. 1100

Alice and Bob are playing a game. They have an array a 1 , a 2 , … , a n a_1, a_2,\ldots,a_n a1​,a2​,…,an​. The game consists of two steps:

  • First, Alice will remove at most k k k elements from the array.
  • Second, Bob will multiply at most x x x elements of the array by − 1 -1 −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 s s of length n n 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 n n quests in the game, numbered from 1 1 1 to n n n.

Monocarp can complete quests according to the following rules:

  • the 1 1 1-st quest is always available for completion;
  • the i i i-th quest is available for completion if all quests KaTeX parse error: Expected 'EOF', got '&' at position 3: j &̲lt; 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 i i-th quest, he gets a i a_i ai​ experience points;
  • for each subsequent completion of the i i i-th quest, he gets b i b_i bi​ experience points.

Monocarp is a very busy person, so he has free time to complete no more than k k k quests. Your task is to calculate the maximum possible total experience Monocarp can get if he can complete no more than k k 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 u u and v v v;
  • Compress all the vertices on the path from u u u to v v v into one vertex. In other words, all the vertices on path from u u u to v v v will be erased from the tree, a new vertex w w w will be created. Then every vertex s s s that had an edge to some vertex on the path from u u u to v v v will have an edge to the vertex w w w.

Illustration of a zelda-operation performed for vertices 1 1 1 and 5 5 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 n n 种方案的最优解。4观察结论还是从小数据更易发现思路,树还是定根更好看。

A1.

  1. 一开始没思考本质出了个假思路:删除最大的min(k,x)个元素。
  2. It is optimal for Bob to negate the x x 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 i i ( 0 ≤ i ≤ k 0 \leq i \leq k 0≤i≤k) where i i i is the number of elements Alice removes. For each i i i, we know that Alice will remove the i i i largest elements of the array and Bob will then negate the x x x largest remaining elements.
  4. 前缀和/扫过去变量维护(细节处理)。

A2.

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

A3.

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

A4.

  1. 出了假思路:每次操作减少一片叶子-> 1 片 / 2 片 1片/2片 1片/2片。
  2. 结论观察。在有根树的视图更易找结论,或从点少的树开始找最优结论:前 n − 1 n-1 n−1 次每次可减少2片叶子。
    We can prove by induction that on any tree with K K K leaves, the answer is [ K + 1 2 ] [{\frac{K + 1}{2}}] [2K+1​], where with [ x ] [x] [x] we denote the greatest integer smaller than x x 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 1 1.
  • For three leaves, the answer is clearly 2 2 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 1 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 3 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 4 4. Furthermore, it reduces the number of leaves in the tree by 2 2 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;
}

标签:2024.12,elements,leaf,23,int,two,will,周一,define
From: https://blog.csdn.net/2302_79354434/article/details/144682891

相关文章

  • 2024.12.25
    鼻子在吸气时感觉疼痛可能由以下几种原因引起:鼻腔干燥:干燥的环境可能导致鼻腔黏膜变得敏感,呼吸时气体直接刺激黏膜,引发疼痛。增加室内湿度或使用生理盐水喷鼻可以缓解这种不适。感染:上呼吸道感染、急性鼻炎等病症可能引起鼻腔黏膜充血水肿,导致呼吸时鼻部出现疼痛。这类病症......
  • Diary - 2024.12.24
    今天作业有点多了,oi时间约等于0。不懂阿,这个数学作业有点太难了,感觉是给mo同学做的。学oi的大家拼尽全力仍无法战胜其中一道,太难了。今天语文课内知识又考炸了,咳咳。放乐观点(。感觉这个学期的语文老师也是有点抽象的。一周只需要考试写作文,评讲就能用掉三四天,然后剩下......
  • 12.23 每日总结(hashmap和hashset)
    今天在做面试题,看到又问hashmap和hashset的区别。HashMap的底层数据结构HashMap在Java中的底层数据结构是一个数组和链表(或红黑树)的组合。具体来说,它是基于一个数组结构,数组中的每个元素是一个链表的头节点。当发生哈希冲突时,即不同的键映射到同一个数组索引位置,这些键值对......
  • 图扑软件荣获 2023 年度福建省科学技术进步奖
    此前,2023年度福建省科学技术奖正式公布,根据《福建省科学技术奖励办法》有关规定,福建省科学技术奖励委员会组织对2023年度福建省科学技术奖进行评审,省政府决定对在科学技术进步活动中作出重要贡献的科学技术人员和组织给予奖励。图扑软件林意炜团队以《面向工业互联网的 2D......
  • Oracle Database 23ai 中的DBMS_HCHECK
    在Oracle23ai中,DBMS_HCHECK包允许我们检查数据库中已知的数据字典问题。 几年前,Oracle发布了hcheck.sql脚本(文档ID136697.1)来检查数据库中已知的数据字典问题。DBMS_HCHECK包意味着我们不再需要下载hcheck.sql脚本来执行此操作。需要hcheck.sql脚本可以留言......
  • 2024.12.24 周四
    2024.12.24周四Q1.1100Youaregivenanarray$a$of$n$positiveintegersandascore.Ifyourscoreisgreaterthanorequalto$a_i$,thenyoucanincreaseyourscoreby$a_i$andremove$a_i$fromthearray.Foreachindex$i$,outputthemaximumnum......
  • 12.23 补一下前面的考试
    软件需求与分析课堂测试十一—综合案例建模分析(100分)销售订货管理系统是ERP的源头,如何管控销售订单下达、评审、跟进,不光是从软件上做约束管理,同时要从工作流程规定上做规范。【开发目的】规范公司订单下达、评审业务流程,提高客户订单准时交货率。【适用范围】适用于公司订......
  • 2024.12.16(周一)
    namespaceDatabase.MainForm{partialclassChangePassword{///<summary>///Requireddesignervariable.///</summary>privateSystem.ComponentModel.IContainercomponents=null;///<summary&......
  • 2024.12.17(周二)
    namespaceDatabase{partialclassLogin{///<summary>///必需的设计器变量。///</summary>privateSystem.ComponentModel.IContainercomponents=null;///<summary>///清理所有正在使用的资源。......
  • 2024.12.19(周四)
    namespaceDatabase.MainForm{partialclassReset{///<summary>///Requireddesignervariable.///</summary>privateSystem.ComponentModel.IContainercomponents=null;///<summary>......