2024.12.20 周五

2024.12.20 周五


Q1. 1000

Ethan runs a vaccination station to help people combat the seasonal flu. He analyses the historical data in order to develop an optimal strategy for vaccine usage.

Consider there are n patients coming to the station on a particular day. The i-th patient comes at the moment ti. We know that each of these patients can be asked to wait for no more than w time moments. That means the i-th patient can get vaccine at moments ti,ti+1,,ti+w.

Vaccines come in packs, each pack consists of k doses. Each patient needs exactly one dose. Packs are stored in a special fridge. After a pack is taken out of the fridge and opened, it can no longer be put back. The lifetime of the vaccine outside the fridge is d moments of time. Thus, if the pack was taken out of the fridge and opened at moment x, its doses can be used to vaccinate patients at moments x,x+1,,x+d. At moment x+d+1 all the remaining unused doses of this pack are thrown away.

Assume that the vaccination station has enough staff to conduct an arbitrary number of operations at every moment of time. What is the minimum number of vaccine packs required to vaccinate all n patients?

Q2. 1000

This is an easy version of the problem. It differs from the hard one only by constraints on n and t.

There is a deck of n cards, each of which is characterized by its power. There are two types of cards:

  • a hero card, the power of such a card is always equal to 0;
  • a bonus card, the power of such a card is always positive.

You can do the following with the deck:

  • take a card from the top of the deck;
  • if this card is a bonus card, you can put it on top of your bonus deck or discard;
  • if this card is a hero card, then the power of the top card from your bonus deck is added to his power (if it is not empty), after that the hero is added to your army, and the used bonus discards.

Your task is to use such actions to gather an army with the maximum possible total power.

Q3. 1000

Dasha loves guinea pigs very much. In this regard, she decided to settle as many guinea pigs at home as possible and developed a plan for the next n days. Every day, she will either buy a new guinea pig or call a doctor to examine all her pets.

Unfortunately, the store where she was going to buy guinea pigs does not understand them. Therefore, it cannot determine their gender. Dasha can't do it either. The only one who can help is a doctor.

To keep guinea pigs, aviaries are needed. Dasha plans to buy them in the same store. Unfortunately, only one species is sold there — a double aviary. No more than two guinea pigs can live in it.

Since Dasha does not want to cause moral injury to her pets — she will not settle two guinea pigs of different genders in one aviary.

Help Dasha calculate how many aviaries in the worst case you need to buy so that you can be sure that at no moment of time do two guinea pigs of different genders live in the same aviary.

As part of this task, we believe that guinea pigs have only two genders — male and female.

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

  • 读题是体力活..>_<

A1.

  1. 对于每个块贪心找到让第一个人等待最久并且疫苗有效的最后时间,双指针扫描实现分块。

A2.

  1. 其实就是遇到非 0 放入集合,遇到 0 选一个最大值加入答案,优先队列秒了。

A3.

  1. 贪心找到一种方案在最坏情况笼子数量,更新就行了。细节wa了一发。

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

A1.

#include <bits/stdc++.h>
using namespace std;
void _();
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        _();
}

void _()
{
    int n, k, d, w;
    cin >> n >> k >> d >> w;
    vector<int> t(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> t[i];
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        res++;
        int maxw = t[i] + w + d;
        int j = i;
        int has = k;
        for (; has && j <= n && t[j] <= maxw; j++)
            has--;
        i = j - 1;
    }
    cout << res << endl;
}

A2.

#include <bits/stdc++.h>

using namespace std;
void _();
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        _();
}

void _()
{
    int n;
    cin >> n;
    priority_queue<int> q;
    long long res = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x)
            q.push(x);
        else
        {
            if (q.size())
            {
                res += q.top();
                q.pop();
            }
        }
    }
    cout << res << endl;
}

A3.

#include <bits/stdc++.h>
using namespace std;
void _();
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        _();
}

void _()
{
    int n;
    cin >> n;
    int male = 0, female = 0;
    auto get = [&]()
    {
        return (male + 1 >> 1) + (female + 1 >> 1);
    };
    int un = 0, res = 0, now_ = 0;
    while (n--)
    {
        int x;
        cin >> x;
        if (x == 1)
        {
            un++;
            res = max(res, now_ + un);
        }
        else
        {
            if (un) // 细节
            {
                if (male)
                    female += un;
                else
                    male = 1, female += un - 1;
            }
            un = 0;
            now_ = get();
            res = max(res, now_);
        }
    }
    cout << res << endl;
}
posted @   Jkke  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示