Lanqiao Cup Takeaway Store 우선 순위 (시뮬레이션) 80 점

시간별로 정렬 한 다음 각 레코드를 차례로 처리합니다. 동시에 주문이 마지막으로 수신 된 시간, 처리 시간 간격을 기록하고 처리 중에 각 주문이 버퍼 대기열에 들어가는 지 (또는 제거되는지) 표시하고 마지막으로 각각을 처리합니다. 주문이 마지막으로 접수 된 순간부터 T까지의 시간입니다.

// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double pi = acos(-1);
//int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int dis[2][2] = {1, 0, 0, 1};
//int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct Node
{
	int ts, id;
} a[maxn];
int last[maxn]; 
bool vis[maxn]; 
int p[maxn];
int n, m, T;
bool cmp(Node a, Node b)
{
	return a.ts < b.ts;
}
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
	IO;
	cin >> n >> m >> T;
	for (int i = 0; i < m; i++)
	{
		cin >> a[i].ts >> a[i].id;
	}
	sort(a, a + m, cmp);
	for (int i = 0; i < m; i++)
	{
		if (p[a[i].id] == 0)
		{
			p[a[i].id] += 2;
		}
		else
		{
			int temp;
			if (last[a[i].id] != a[i].ts)
				temp = a[i].ts - last[a[i].id] - 1;
			else
				temp = 0;
			p[a[i].id] -= temp;
			if (p[a[i].id] < 0)
				p[a[i].id] = 0;
			p[a[i].id] += 2;
			if (p[a[i].id] > 5)
				vis[a[i].id] = true;
			if (p[a[i].id] <= 3)
				vis[a[i].id] = false;
		}
		last[a[i].id] = a[i].ts;
	}
	for (int i = 1; i <= n; i++)
	{
		int temp;
		if (last[i] != T)
			temp = T - last[i];
		else
			temp = 0;
		p[i] -= temp;
		if (p[i] < 0)
			p[i] = 0;
		if (p[i] > 5)
			vis[i] = true;
		if (p[i] <= 3)
			vis[i] = false;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		if (vis[i] == true)
			ans++;
	cout << ans;
	return 0;
}

 

추천

출처blog.csdn.net/qq_44115065/article/details/109081355