2025 ICPC Wuhan Invitational Contest (The 3rd Universal Cup. Stage 37: Wuhan)vp补题

赛时3题,vp铁

A. Problem Setting

知识点:签到,无

思路:预处理每个属性的取值范围,如果 \(l>r\) ,那么无解得到 \(-1\),如果 \(l<r\),根据 \(a_i\) 的大小进行累加即可

I. Bingo 3

知识点:构造

思路:在 \((1,1)\) 处放 \(k\),在对角线上放比 \(k\) 大的数,在第一行放 \(k\)\(1到 n-1\),其他数随便填,无解的情况应该是无法构造出第一行或对角线,判定条件为 \(k<n\)\(k>n^2-n+1\)

L. Subsequence

知识点:枚举,贪心

思路:遍历数组,把每一个数当作中位数,定义 \(l=1\)\(r=n\) 两个指针,如果满足 \(a_i*2==a_r+a_l\),应当取左右序列的较小值,还要通过大小来处理最终序列的构造情况

Code
点击查看代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
void _()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a.begin() + 1, a.end());
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int l = 1, r = n;
        while (l <= r)
        {
            if ((a[l] + a[r]) % 2 == 0 && a[l] + a[r] == 2 * a[i])
            {
                if (r - i == i - l)
                {
                    ans = max(ans, 2 * (r - i) + 1);
                    break;
                }
                else if (r - i - 1 == i - l)
                {
                    ans = max(ans, 2 * (r - i));
                    break;
                }
                else if (i - l <= r - i - 1)
                {
                    r--;
                }
                else
                {
                    l++;
                }
            }
            else if (a[l] + a[r] <= 2 * a[i])
            {
                l++;
            }
            else
            {
                r--;
            }
        }
    }
    cout << ans << '\n';
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

F. Knapsack

知识点:贪心

思路:按 \(b_i\) 从小到大排序,先处理最大的,平均放,多的余出来,计算还能放多少 \(res\),计算当前的最大值 \(mx\),再处理更小的,倒序遍历,如果发现剩下的空间可以装下当前物品,就直接更新 \(res\),如果不能装下,那就把没处理的物品按照放最大重量的物品那样放到背包里,更新 \(res\)\(mx\),如果相邻物品组的重量差距过大,直接定义 \(res\) 为一个极大值即可

Code

点击查看代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define x first
#define y second
const int INF = 3e14;
const int mod = 998244353;
int ksm(int a, int b, int c)
{
    int ans = 1;
    a %= c;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a % c;
        }
        b >>= 1;
        a = a * a % c;
    }
    return ans;
}
void _()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].y >> a[i].x;
    }
    sort(a.begin() + 1, a.end());
    int res = 0;
    int pre = 0;
    int mx = 0;
    for (int i = n; i >= 1; i--)
    {
        int cha = 0;
        if (i == n)
        {
            int cnt = (a[i].y + m - 1) / m;
            res = cnt * m - a[i].y;
            mx = cnt % mod * ksm(2, a[i].x, mod) % mod;
            pre = a[i].x;
            continue;
        }
        if (pre - a[i].x > 0 && res > 0)
        {
            if (pre - a[i].x > 63)
            {
                res = INF;
            }
            else
            {
                if (res > INF / (1LL << (pre - a[i].x)))
                {
                    res = INF;
                }
                else
                {
                    res = res * (1LL << (pre - a[i].x));
                }
            }
        }

        cha = ksm(2, pre - a[i].x, mod);
        int need = a[i].y;
        if (res < need)
        {
            need -= res;
            int cnt = (need + m - 1) / m;
            res = cnt * m - need;
            mx = (mx + cnt % mod * ksm(2, a[i].x, mod) % mod) % mod;
        }
        else
        {
            res -= need;
        }
        pre = a[i].x;
    }

    cout << mx << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}
posted @ 2026-04-29 20:05  Lambda_L  阅读(11)  评论(0)    收藏  举报