【正经题解】外卖店优先级
2024-03-15 11:16:13
发布于:浙江
6阅读
0回复
0点赞
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII; // 使用 PII 表示一个包含两个整数的 pair
const int N = 100010;
int n, m, T;
int priority[N], lastOrder[N];
bool inCache[N];
PII orders[N];
int main()
{
scanf("%d%d%d", &n, &m, &T); // 输入外卖店数量n、订单数量m、和时刻T
for (int i = 0; i < m; i++)
scanf("%d%d", &orders[i].first, &orders[i].second); // 输入每个订单的时刻和外卖店编号
sort(orders, orders + m); // 按照时刻对订单进行排序
for (int i = 0; i < m;)
{
int j = i;
while (j < m && orders[j] == orders[i])
j++;
int time = orders[i].first, id = orders[i].second, count = j - i;
i = j;
// 处理 t 时刻之前的信息
priority[id] -= time - lastOrder[id] - 1;
if (priority[id] < 0)
priority[id] = 0;
if (priority[id] <= 3)
inCache[id] = false;
// 处理 t 时刻的信息
priority[id] += count * 2;
if (priority[id] > 5)
inCache[id] = true;
lastOrder[id] = time;
}
for (int i = 1; i <= n; i++)
if (lastOrder[i] < T)
{
priority[i] -= T - lastOrder[i];
if (priority[i] <= 3)
inCache[i] = false;
}
int result = 0;
for (int i = 1; i <= n; i++)
result += inCache[i];
printf("%d\n", result); // 输出结果
return 0;
}
这里空空如也
有帮助,赞一个