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
Vaccines come in packs, each pack consists of
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
Q2. 1000
This is an easy version of the problem. It differs from the hard one only by constraints on
There is a deck of
- a hero card, the power of such a card is always equal to
; - 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
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.
- 对于每个块贪心找到让第一个人等待最久并且疫苗有效的最后时间,双指针扫描实现分块。
A2.
- 其实就是遇到非
放入集合,遇到 选一个最大值加入答案,优先队列秒了。
A3.
- 贪心找到一种方案在最坏情况笼子数量,更新就行了。细节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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!