C++
\color{gold}{— > 蓝桥杯辅导课题解}
思路:
模拟
将所有订单按照时间进行排序,遍历每个订单,每次处理一批相同的订单,对其进行操作
#include <iostream>
#include <cstring>
#include <algorithm>
#define x first
#define y second
using namespace std;
const int N = 1e5 + 10;
typedef pair<int, int> pii;
int n, m, T;
int score[N], last[N];
bool st[N]; // 判断是否在优先缓存中
pii order[N];
int main() {
cin >> n >> m >> T;
for (int i = 0; i < m; i ++) cin >> order[i].x >> order[i].y;
sort(order, order + m); // pair双关键字排序
for (int i = 0; i < m;) {
int j = i;
while (j < m && order[j] == order[i]) j ++;
int t = order[i].x, id = order[i].y, cnt = j - i;
i = j;
score[id] -= t - last[id] - 1; // 处理一下t-1时刻这家店距离上个订单中间的空隔导致的优先级降低
if (score[id] < 0) score[id] = 0;
if (score[id] <= 3) st[id] = false; // 以上处理的是t时刻之前的信息
score[id] += cnt * 2; // 处理t时刻这家店的优先级
if (score[id] > 5) st[id] = true; // 符合条件,加入缓存中
last[id] = t; // 记录这个有订单的时刻
}
for (int i = 1; i <= n; i ++)
if (last[i] < T) { // 处理店的最后有订单的时刻与T时刻的间隔导致的优先级降低
score[i] -= T - last[i];
if (score[i] <= 3) st[i] = false;
}
int res = 0;
for (int i = 1; i <= n; i ++) res += st[i];
cout << res;
return 0;
}