当前位置: 首页 > article >正文

2024.12.27 周五

2024.12.27 周五


Q1. 1100

Alex is participating in the filming of another video of BrMeast, and BrMeast asked Alex to prepare 250 thousand tons of TNT, but Alex didn’t hear him well, so he prepared n n n boxes and arranged them in a row waiting for trucks. The i i i-th box from the left weighs a i a_i ai tons.

All trucks that Alex is going to use hold the same number of boxes, denoted by k k k. Loading happens the following way:

  • The first k k k boxes goes to the first truck,
  • The second k k k boxes goes to the second truck,
  • ⋯ \dotsb
  • The last k k k boxes goes to the n k \frac{n}{k} kn-th truck.

Upon loading is completed, each truck must have exactly k k k boxes. In other words, if at some point it is not possible to load exactly k k k boxes into the truck, then the loading option with that k k k is not possible.

Alex hates justice, so he wants the maximum absolute difference between the total weights of two trucks to be as great as possible. If there is only one truck, this value is 0 0 0.

Alex has quite a lot of connections, so for every 1 ≤ k ≤ n 1 \leq k \leq n 1kn, he can find a company such that each of its trucks can hold exactly k k k boxes. Print the maximum absolute difference between the total weights of any two trucks.


Q2. 1100

You are given an array a a a of length n n n, consisting of positive integers, and an array x x x of length q q q, also consisting of positive integers.

There are q q q modification. On the i i i-th modification ( 1 ≤ i ≤ q 1 \leq i \leq q 1iq), for each j j j ( 1 ≤ j ≤ n 1 \leq j \leq n 1jn), such that a j a_j aj is divisible by 2 x i 2^{x_i} 2xi, you add 2 x i − 1 2^{x_i-1} 2xi1 to a j a_j aj. Note that x i x_i xi ( 1 ≤ x i ≤ 30 1 \leq x_i \leq 30 1xi30) is a positive integer not exceeding 30.

After all modification queries, you need to output the final array.


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

  • 这两道题都和数学有些关系,暴力会超时,通过数学与前缀优化解决。


A1.

  1. 读懂题就是:对于每个可被n整除的数作为一个长度k,对每个长度将n分为n/k连续的块,问块和的最大差值。
  2. 因数最多为 l o g n logn logn ,前缀和优化,时间复杂度 O ( n l o g n ) O(nlogn) O(nlogn)
  3. 初始化最大值上界开小了(区间和),wa一发。

A2.

  1. 若要被 2 x 2^x 2x 整除,其后 x x x 位需要全为 0 0 0 ,加上 1 < < x − 1 1<<x-1 1<<x1 后,再次遇到 x x x 就不会有贡献,即需要发现的点是q数组中的数只有第一次出现才会有贡献,因此最多 30 30 30 个,两层暴力即可。

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

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;
    cin >> n;
    vector<int> pre(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> pre[i], pre[i] += pre[i - 1];
    auto ask = [&](int l, int r)
    {
        return pre[r] - pre[l - 1];
    };
    vector<int> op;
    for (int i = 1; i <= n; i++)
        if (n % i == 0)
            op.push_back(i);
    int res = 0;
    auto get = [&](int d)
    {
        int l = 1, r = d;
        int maxw = 0, minw = 1e18;
        while (r <= n)
        {
            maxw = max(maxw, ask(l, r));
            minw = min(minw, ask(l, r));
            l+=d,r+=d;
        }
        return maxw - minw;
    };
    for (auto d : op)
        res = max(res, get(d));
    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, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int &x : a)
        cin >> x;
    int has[31] = {}; // map自动排序 无法保证原始序列
    vector<int> b;
    while (q--)
    {
        int x;
        cin >> x;
        if (!has[x])
            b.push_back(x);
        has[x] = 1;
    }

    for (auto &x : b)
        for (auto &a : a)
        {
            int v = 1ll << x;
            // bug(v);
            a += a % v == 0 ? (v >> 1) : 0;
        }
    for (auto v : a)
        cout << v << ' ';
    cout << endl;
}


http://www.kler.cn/a/456709.html

相关文章:

  • Go小技巧易错点100例(十九)
  • 30天开发操作系统 第 10 天 -- 叠加处理
  • STM32配合可编程加密芯片SMEC88ST的防抄板加密方案设计
  • 大数据技术(六)—— Hbase集群安装
  • HTML5 开关(Toggle Switch)详细讲解
  • vue3 ref reactive响应式数据,赋值的问题、解构失去响应式问题
  • STM32-笔记13-红外避障模块-LCD1602模块
  • 基于单片机的抽油烟机自动控制无级调速电路设计
  • 智能工厂的设计软件 应用场景的一个例子:为AI聊天工具添加一个知识系统 之2
  • QML 之过渡
  • MySQL Workbench菜单汉化为中文
  • WPF使用资源定义和样式资源,解耦视图与逻辑(较多样式重复的时候使用)
  • 有没有免费提取音频的软件?音频编辑软件介绍!
  • 【深度学习基础之多尺度特征提取】特征金字塔(Feature Pyramid)是如何在深度学习网络中提取多尺度特征的?附代码
  • curl -fsSL https://get.docker.com|sh 解释命令
  • Pytorch | 利用GRA针对CIFAR10上的ResNet分类器进行对抗攻击
  • doris集群存储目录切换
  • Function.prototype和Object.prototype 的区别
  • 【自动驾驶】3 激光雷达③
  • webflux版定时任务实现方案
  • LeetCode 242. 有效的字母异位词 (C++实现)
  • 超短波自组网如何守护森防安全?
  • Jmeter自学【8】- 使用JMeter模拟设备通过MQTT发送数据
  • AI开发 - 算法基础 递归 的概念和入门(一) 递归算法的常见应用 PYTHON
  • STM32第十一课:STM32-基于标准库的42步进电机的简单IO控制(附电机教程,看到即赚到)
  • Gavin Wood 的 Polkadot 2024 年度回顾:技术突破与未来的无限可能