?
?
1≤N,M,T≤1051≤�,�,�≤105,
1≤ts≤T1≤��≤�,
1≤id≤N1≤��≤�
2 6 6
1 1
5 2
3 1
6 2
2 1
6 2
1
66?时刻时,11?号店优先级降到?33,被移除出优先缓存;22?号店优先级升到?66,加入优先缓存。
所以是有?11?家店 (22?号) 在优先缓存中。
?
?
#include <cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
//数组最大定义到万
bool st[10010];
int order[10010][10010];
int score[10010];
int res;
int main()
{
int N, M, T;
cin >> N >> M >> T;
while (M--) {
int t, id;
cin >> t >> id;
order[t][id] += 1;//某时刻某卖店订单数
}
//遍历计算每个卖店在每个时刻的优先级,推至时刻T为止
for (int id = 1; id <= N; id++) {
for (int t = 1; t <= T; t++) {
if (order[t][id] > 0) {
score[id] += order[t][id] * 2;
}
else
{
if (score[id] - 1 >= 0)
score[id]--;
}
if (score[id] > 5)st[id] = true;
if (score[id] <= 3)st[id] = false;
}
}
//计算在优先缓存区的数量
for (int id = 1; id <= N; id++)res += st[id];
cout << res;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100010
#define x first
#define y second
typedef pair<int, int>PII;
PII order[N];
int score[N];
int last_order_time[N];
bool st[N];
int main()
{
int n, m, T;
cin >> n >> m >> T;
//输入订单,x表示时刻,y表示卖点编号
for (int i = 0; i < m; i++)scanf("%d%d", &order[i].x, &order[i].y);
//订单按照时间(先)和编号(后)排序
sort(order, order + m);//pair<>的sort排序是系统内设的,无需自定义
//遍历输入的每一个订单
for (int i = 0; i < m;) {
int id = order[i].y, t = order[i].x;
score[id] -= t - last_order_time[id] - 1;
if (score[id] < 0)score[id] = 0;
if (score[id] <= 3)st[id] = false;
//以上是处理有订单时刻t之前的信息
//计算同一时刻同一卖店的订单数量
int j = i, cnt = 0;
while (j < m && order[i] == order[j])j++;
cnt = j - i;
i = j;
score[id] += cnt * 2;
if (score[id] > 5)st[id] = true;
last_order_time[id] = t;//更新上一次有订单的时间为当前有订单的时间
}
//考虑最后的last_order_time到T时刻
for (int id = 1; id <= n; id++) {
if (last_order_time[id] < T)
score[id] -= (T - last_order_time[id]);
if (score[id] <= 3)st[id] = false;
}
//T时刻外卖店在优先缓存中的数量
int res = 0;
for (int id = 1; id <= n; id++)res += st[id];
cout << res;
}