首页 > 其他分享 >2022 CCPC 绵阳AE

2022 CCPC 绵阳AE

时间:2024-10-08 19:50:07浏览次数:3  
标签:cnt AE int CCPC turn 2022 np1 dp np2

2022 CCPC 绵阳

A. Ban or Pick, What’s the Trick?

题面描述:

红蓝双方有一个大小为 n n n 的英雄池,每次操作一方可以选择一个英雄或者 b a n ban ban 掉对方的一个英雄,每个英雄含有权值 v v v,求双方在最有策略下英雄权值之和的差(蓝方先操作)。

基本思路:

题目所给最大可选英雄数量为 10 10 10,则考虑 n × 10 × 10 n \times 10 \times 10 n×10×10 的 d p dp dp设当前进行的轮数为 t u r n turn turn,则之前红方操作的次数 t u r n b turnb turnb为 ⌊ t u r n − 1 2 ⌋ \lfloor{ turn-1\over 2}\rfloor ⌊2turn−1​⌋,蓝方操作次数为 t u r n − 1 − t u r n b turn-1-turnb turn−1−turnb,将英雄按权值进行排序后,计算出 b a n , p i c k ban,pick ban,pick 所对应的英雄,判断合法性后进行 d f s dfs dfs,并使用记忆化搜索降低时间复杂度

代码:
#include <bits/stdc++.h>
using namespace std;
// #define int long long int
#define Paddi ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 4e5 + 10;
int n, k;
int dp[N][15][15];
vector<int> s1;
vector<int> s2;
const int Inf = 1e18;
int dfs(int turn, int np1, int np2)
{
    if (turn > 2 * n)
        return 0;
    if ((dp[turn][np1][np2] != Inf) and (dp[turn][np1][np2] != -Inf))
        return dp[turn][np1][np2];
    int turnb = (turn - 1) / 2;
    int turna = (turn - 1) - turnb;
    int pos1 = turnb - np2 + np1;
    int pos2 = turna - np1 + np2;
    if (turn % 2 == 1)
    {
        int cnt = -Inf;
        if ((pos1 != n) and (np1 != k))
            cnt = max(cnt, dfs(turn + 1, np1 + 1, np2) + s1[pos1]);
        if (pos2 != n)
            cnt = max(cnt, dfs(turn + 1, np1, np2));
        return dp[turn][np1][np2] = cnt;
    }
    else
    {
        int cnt = Inf;
        if ((pos2 != n) and (np2 != k))
            cnt = min(cnt, dfs(turn + 1, np1, np2 + 1) - s2[pos2]);
        if (pos1 != n)
            cnt = min(cnt, dfs(turn + 1, np1, np2));
        return dp[turn][np1][np2] = cnt;
    }
}
int main()
{
    Paddi;
    cin >> n >> k;
    s1.resize(n);
    s2.resize(n);
    for (int i = 0; i < n; i++)
        cin >> s1[i];
    for (int i = 0; i < n; i++)
        cin >> s2[i];
    sort(s1.begin(), s1.end(), greater<int>());
    sort(s2.begin(), s2.end(), greater<int>());
    for (int i = 0; i <= 2 * n + 10; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            for (int h = 0; h <= k; h++)
            {
                if (i % 2 == 0)
                    dp[i][j][h] = Inf;
                else
                    dp[i][j][h] = -Inf;
            }
        }
    }
    int ans = dfs(1, 0, 0);
    cout << ans << endl;

    return 0;
}

E. Hammer to Fall

题面描述:

你有一张无向带权图 G G G,已知每一天被砸中的节点为 q i q_i qi​,在某个节点被砸中之前,你要将所有在该节点上的人转移到相邻的节点,每个人转移的费用为该边的权值 w w w.求所需要的最小权值.

基本思路:

发现每个人的转移都是独立的,我们发现转移要考虑后续被砸中的节点,故我们考虑倒序 d p dp dp,从后往前遍历被砸中的节点 x x x,有
d p [ x ] = m i n ( x , y , w ) ∈ G d p [ y ] + w dp[x]=min_{(x,y,w) \in G} dp[y]+w dp[x]=min(x,y,w)∈G​dp[y]+w
最暴力的想法是遍历每个相邻的节点。但是发现当某写节点连边数量较大时会超时。考虑到对节点所连边的数量进行分开处理。

对于小于边界的节点,我们暴力枚举每一个相邻的节点,对于大于边界的节点,我们用 s t d : s e t std: set std:set维护。

我们更新完一个节点后,将大于边界的节点的 s e t set set 全部进行更新。

设边界为 t t t,则时间复杂度为 O ( q ( t + 2 m t l o g n ) ) O(q(t+{2m\over t} logn)) O(q(t+t2m​logn))

利用基本不等式, t = 2 m l o g n t= \sqrt {2mlogn} t=2mlogn

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define Paddi ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#pragma GCC optimize(2)
const int N = 2e5 + 10;
struct Node
{
    int v, w;
};
int read()
{
    int x = 0, w = 1;
    char ch = 0;
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * w;
}

vector<struct Node> e[N], big[N];
set<array<int, 3>> now[N];
int dp[N], d[N], peo[N];
const int Mod = 998244353;
int n, m, q;
signed main()
{
    n = read(), m = read(), q = read();
    int t = sqrt(2 * m * log(n));
    for (int i = 1; i <= n; i++)
        peo[i] = read();
    for (int i = 1; i <= m; i++)
    {
        int u, v, w;
        u = read(), v = read(), w = read();
        e[u].push_back({v, w});
        e[v].push_back({u, w});
        d[u]++, d[v]++;
    }
    for (int i = 1; i <= n; i++)
    {
        for (auto j : e[i])
            now[i].insert({j.w, j.v, j.w});
        for (auto j : e[i])
        {
            if (d[j.v] >= t)
                big[i].push_back({j.v, j.w});
        }
    }
    vector<int> query(q);
    for (int i = 0; i < q; i++)
        query[i] = read();
    reverse(query.begin(), query.end());
    for (int i = 0; i < q; i++)
    {
        int x = query[i];
        int last = dp[x];
        if (d[x] >= t)
        {
            auto it = *now[x].begin();
            dp[x] = it[0];
        }
        else
        {
            int mi = 1e18;
            for (auto j : e[x])
                mi = min(mi, dp[j.v] + j.w);
            dp[x] = mi;
        }
        for (auto j : big[x])
        {
            array<int, 3> a;
            a[0] = last + j.w, a[1] = x, a[2] = j.w;
            auto it = now[j.v].lower_bound(a);
            now[j.v].erase(it);
            now[j.v].insert({dp[x] + j.w, x, j.w});
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = (ans + (dp[i] * peo[i]) % Mod) % Mod;
    printf("%lld\n", ans % Mod);
    return 0;
}

标签:cnt,AE,int,CCPC,turn,2022,np1,dp,np2
From: https://blog.csdn.net/2302_80542709/article/details/142767878

相关文章

  • 20222325 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容缓冲区溢出基本知识:堆栈、函数调用。shellcode技术以及其在各平台的运用与防御。BOF攻击防御技术。2.实验目标本次实践的对象是一个名为pwn1的linux可执行文件。该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串。该程序同时包含另......
  • 20222310 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    一、实验内容1.实验目标本次实验的对象是一个名为pwn1的linux可执行文件。该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串。该程序同时包含另一个代码片段,getShell,会返回一个可用Shell。正常情况下这个代码是不会被运行的。我们实验的目标就是想......
  • YOLO11改进|卷积篇|引入轻量级自适应提取卷积LAE
    目录一、【LAE】卷积1.1【LAE】卷积介绍1.2【LAE】核心代码二、添加【LAE】卷积机制2.1STEP12.2STEP22.3STEP32.4STEP4三、yaml文件与运行3.1yaml文件3.2运行成功截图一、【LAE】卷积1.1【LAE】卷积介绍下图是【LAE】卷积的结构图,让我们简单分析一下运行过程......
  • 记一次升级系统补丁导致 VS2022 崩溃分析
    一:背景1.讲故事在最近一两年内VisualStudio2022会偶发的出现打开即崩溃的情况,本想着把VS卸载重装,但发现这东西想卸载干净还是蛮困难的,又加上我这个人比较懒,所以就直接重装系统了,最近的9月份因为它重装了一次系统,但过了一天又遇到了同样的问题,在这样一个背景下我决定认真的看......
  • 20222420 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1.1学习内容总结1.1.1初步了解缓冲区溢出漏洞首先学习了安全漏洞的相关概念,然后聚焦在其中的缓冲区溢出漏洞上。学习了缓冲区溢出漏洞相关的定义和发生的原因,并了解了缓冲区溢出发展历史上的经典攻击,如红色代码蠕虫、冲击波病毒、震荡波病毒、心脏出血、乌克兰断网......
  • JOISC 2022
    JOISC2022Day1T2京都观光在zr的时候花子讲过这个题,当时就觉得非常的震撼!!现在来看还是觉得这个题好牛啊。假设我们现在只有两条路走:第一条是↓→,第二条是→↓。贡献分别为:\(B_1\timesn+A_n\timesm\)以及\(A_1\timesm+B_m\timesn\)。移项后两侧分别为\((A_n-A_1)\t......
  • 2024CCPC山东省赛补题记录
    前言今天和队友VP了24CCPC山东省赛,最后9题,但是赛中7题左右我就隐身了,赛后看题解发现E题不难,赛时过的人太少导致有点畏手畏脚,看到题解一下就懂了,几分钟写好。这里主要补一下E和L的题解,这场比赛学到了维护区间信息,可以考虑把区间挂在线段树节点上,以及动态维护树直径的典。E传感器......
  • P8392 [BalticOI 2022 Day1] Uplifting Excursion(特殊背包问题)
    题意简述有\(2m+1\)种物品,体积分别为\(-m\simm\),每种物品有\(a_i\)个。你需要选出尽可能多数量的物品,使得物品体积和为\(l\)。\(m\le300,a_i,|l|\le10^{18}\)分析此题属于“背包容量极大,物品体积极小”的特殊背包问题。考虑背包问题的经典错误贪心:按照性价比降序排......
  • 20222315 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1.掌握反汇编与十六进制编程器2.能正确修改机器指令改变程序执行流程3.能正确构造payload进行bof攻击2.实验过程1.直接修改程序机器指令,改变程序执行流程将pwn1文件下载至kali中并将pwn1文件改名为pwn20222315,并将其内容复制到pwn2反汇编文件objdump-dpwn2022231......
  • 20222301 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    一、实验目的本次实践的对象是一个名为pwn1的linux可执行文件。该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串。该程序同时包含另一个代码片段,getShell,会返回一个可用Shell。正常情况下这个代码是不会被运行的。我们实践的目标就是想办法运行这个......