2024.12.24 周四

2024.12.24 周四


Q1. 1100

You are given an array a of n positive integers and a score. If your score is greater than or equal to ai, then you can increase your score by ai and remove ai from the array.

For each index i, output the maximum number of additional array elements that you can remove if you remove ai and then set your score to ai. Note that the removal of ai should not be counted in the answer.


Q2. 1100

Monocarp is a student at Berland State University. Due to recent changes in the Berland education system, Monocarp has to study only one subject — programming.

The academic term consists of n days, and in order not to get expelled, Monocarp has to earn at least P points during those n days. There are two ways to earn points — completing practical tasks and attending lessons. For each practical task Monocarp fulfills, he earns t points, and for each lesson he attends, he earns l points.

Practical tasks are unlocked "each week" as the term goes on: the first task is unlocked on day 1 (and can be completed on any day from 1 to n), the second task is unlocked on day 8 (and can be completed on any day from 8 to n), the third task is unlocked on day 15, and so on.

Every day from 1 to n, there is a lesson which can be attended by Monocarp. And every day, Monocarp chooses whether to study or to rest the whole day. When Monocarp decides to study, he attends a lesson and can complete no more than 2 tasks, which are already unlocked and not completed yet. If Monocarp rests the whole day, he skips a lesson and ignores tasks.

Monocarp wants to have as many days off as possible, i. e. he wants to maximize the number of days he rests. Help him calculate the maximum number of days he can rest!


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

  • 用时:35 28。Q1有点思维。Q2是3状态贪心。

A1.

  1. 排序之后发现前面的一定可以选取,后面到某一个临界值。假思路:二分,没有仔细证明答案二段性。
  2. 从当前向后一个个找复杂度较高,考虑快速查找,em.. 倒序考虑:pre[i]>=a[i+1]f[i]=f[i+1]elsef[i]=i1
  3. 倒叙可行性的本质就是:利用后面的答案,先计算后面的答案可以让前面快速找到答案。遍历思想,数据维护,转移答案,有dp的味道。

A2.

  1. 那么一大堆就是:读好题意,贪心计算3个阶段。

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

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;
    struct Node
    {
        /* data */
        int x, i, f;
    };
    vector<Node> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].x;
        a[i].i = i;
    }
    sort(a.begin() + 1, a.end(), [](Node &a, Node &b)
         { return a.x > b.x; });
    vector<int> pre(n + 1);
    for (int i = 1; i <= n; i++)
        pre[i] = pre[i - 1] + a[i].x;

    for (int i = 1; i <= n; i++)
        if (i == 1)
            a[i].f = n - 1;
        else
        {
            if (pre[n] - pre[i - 1] >= a[i - 1].x)
                a[i].f = a[i - 1].f;
            else
                a[i].f = n - i;
        }

    sort(a.begin(), a.end(), [](Node &a, Node &b)
         { return a.i < b.i; });
    for (int i = 1; i <= n; i++)
        cout << a[i].f << " ";
    cout << endl;
}
// void _()
// {
//     int n;
//     cin >> n;
//     struct Node
//     {
//         /* data */
//         int x, i, res;
//     };
//     vector<Node> a(n + 1);
//     for (int i = 1; i <= n; i++)
//     {
//         cin >> a[i].x;
//         a[i].i = i;
//     }
//     sort(a.begin(), a.end(), [](Node &a, Node &b)
//          { return a.x < b.x; });
//     vector<int> pre(n + 1);
//     for (int i = 1; i <= n; i++)
//         pre[i] = pre[i - 1] + a[i].x;
//     auto ok = [&](int x)
//     {
//         return pre[x - 1] >= a[x].x;
//     };
//     for (int i = 1; i <= n; i++)
//     {
//         int l = i, r = n + 1;
//         while (r - l - 1)
//         {
//             int mid = l + r >> 1;
//             if (ok(mid))
//                 l = mid;
//             else
//                 r = mid;
//         }
//         bug2(i, l);
//         a[i].res = l - 1;
//     }
//     sort(a.begin(), a.end(), [](Node &a, Node &b)
//          { return a.i < b.i; });
//     for (int i = 1; i <= n; i++)
//         cout << a[i].res << " ";
//     cout << 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, p, t, l;
    cin >> n >> p >> l >> t;
    auto cal = [](int a, int b)
    {
        return (a + b - 1) / b;
    };
    int has = cal(n, 7);
    int ned = cal(p, t * 2 + l);
    int res = min(has / 2, ned);
    p -= res * (t * 2 + l);
    // bug(p);
    if (p > 0)
    {
        if (has & 1)
            res++, p -= t + l;
    }
    if (p > 0)
        res += cal(p, l);
    res = min(res, n);
    cout
        << n - res << endl;
}
// void _()
// {
//     int n, p, t, l;
//     cin >> n >> p >> l >> t;
//     auto cal = [](int a, int b)
//     {
//         return (a + b - 1) / b;
//     };
//     int has = cal(n, 7);
//     int ned = cal(p, t * 2 + l);
//     int res = min(has, ned);
//     if (ned > has)
//     {
//         p -= has * (t * 2 + l);
//         res += cal(p, l);
//         res = min(n, res);
//     }
//     cout << n - res << endl;
// }
posted @   Jkke  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示