2024.12.22 周日

2024.12.22 周日


Q1. 1100

You are playing a computer game. The current level of this game can be modeled as a straight line. Your character is in point 0 0 0 of this line. There are n n n monsters trying to kill your character; the i i i-th monster has health equal to a i a_i ai and is initially in the point x i x_i xi.

Every second, the following happens:

  • first, you fire up to k k k bullets at monsters. Each bullet targets exactly one monster and decreases its health by 1 1 1. For each bullet, you choose its target arbitrary (for example, you can fire all bullets at one monster, fire all bullets at different monsters, or choose any other combination). Any monster can be targeted by a bullet, regardless of its position and any other factors;
  • then, all alive monsters with health 0 0 0 or less die;
  • then, all alive monsters move 1 1 1 point closer to you (monsters to the left of you increase their coordinates by 1 1 1, monsters to the right of you decrease their coordinates by 1 1 1). If any monster reaches your character (moves to the point 0 0 0), you lose.

Can you survive and kill all n n n monsters without letting any of them reach your character?


Q2. 1100

Petya has an array a i a_i ai of n n n integers. His brother Vasya became envious and decided to make his own array of n n n integers.

To do this, he found m m m integers b i b_i bi ( m ≥ n m\ge n mn), and now he wants to choose some n n n integers of them and arrange them in a certain order to obtain an array c i c_i ci of length n n n.

Vasya wants to make his array as different as possible from Petya’s array. Specifically, he wants the total difference D = ∑ i = 1 n ∣ a i − c i ∣ D = \sum_{i=1}^{n} |a_i - c_i| D=i=1naici to be as large as possible.

Help Vasya find the maximum difference D D D he can obtain.


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

  • 2道贪心

A1.

  1. 设定距离数组:距离为 i i i 时怪物血量总和。检查每一个 i ∗ k < = p r e [ i ] i*k<=pre[i] ik<=pre[i]

A2.

  1. 一道有意思的贪心,想了很久,证明略难…

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

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;
    cin >> n >> k;
    vector<int> a(n), x(n), pre(n + 1);
    for (int &x : a)
        cin >> x;
    for (int &x : x)
        cin >> x;
    for (int i = 0; i < n; i++)
        pre[abs(x[i])] += a[i];
    bool res = 1;
    for (int i = 1; i <= n; i++)
    {
        pre[i] += pre[i - 1];
        if (pre[i] > k * i)
            res = 0;
    }
    cout << (res ? "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, m;
    cin >> n >> m;
    struct Node
    {
        /* data */
        int x, i;
    };

    vector<Node> a(n + 1);
    vector<int> b(m + 1), res(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i].x, a[i].i = i;
    for (int i = 1; i <= m; i++)
        cin >> b[i];
    sort(a.begin() + 1, a.end(), [](Node &a, Node &b)
         { return a.x < b.x; });
    sort(b.begin() + 1, b.end());
    int la = 1, ra = n, lb = 1, rb = m;
    while (la <= ra)
    {
        if (abs(a[la].x - b[rb]) > abs(a[ra].x - b[lb]))
            res[la] = b[rb], la++, rb--;
        else
            res[ra] = b[lb], ra--, lb++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans += abs(a[i].x - res[i]);
    // cout << res[i] << ' ';
    cout << ans << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值