AcWing1241. 外卖店优先级
外卖店优先级
一定对的做法,模拟每个时刻的情况
- 判断哪些店有订单哪些店没有订单
- 10^5次方
- 离散的有很多个订单,把中间压缩掉,连续没有订单的,放到购买订单那里处理
将所有订单按照时间顺序排序,一次处理一批订单相同的订单,相同时刻
模拟题伪代码比较重要
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int maxn = 1e5 + 10;
int score[maxn], last[maxn];
PII order[maxn];
bool st[maxn];
int n, m, t;
int main()
{
cin >> n >> m >> t;
for (int i = 0; i < m; i++)
{
scanf("%d %d", &order[i].x, &order[i].y);
}
sort(order, order + m);
for(int i = 0; i < m;)
{
int j = i;
while(j < m && order[j] == order[i]) j ++;
int cnt = j - i; // 某一时刻订单的数量
int ts = order[i].x;
int id = order[i].y;
i = j;
score[id] -= ts - last[id] - 1;
if(score[id] < 0) score[id] = 0;
if(score[id] <= 3) st[id] = false;
score[id] += cnt * 2;
if(score[id] > 5) st[id] = true;
last[id] = ts;
}
for (int i = 1; i <= n; i++) // 处理1-n,因为有可能有些订单没有出现店名
{
if(last[i] < t)
{
score[i] -= t - last[i];
if(score[i] <= 3) st[i] = false;
}
}
int res;
for(int i = 1; i <= n; i ++) res += st[i]; // 处理1-n
cout << res << endl;
return 0;
}
有什么问题可以加qq:1281372141进行交流