Problem Solving/BOJ(백준)

[BOJ]백준 22234번: 가희와 은행(C++)/Priority Queue

이진2 2021. 8. 15. 21:39

https://www.acmicpc.net/problem/22234

 

22234번: 가희와 은행

가희는 창구가 하나인 은행을 운영하고 있습니다. 가희의 은행이 영업을 시작했을 때, 대기 줄에는 손님이 N명 있습니다. [그림 1] 카운터 직원과 N명의 손님 x번 손님에 대한 정보는 x번 손님의

www.acmicpc.net

운영체제 CPU 스케줄링 알고리즘인 라운드-로빈을 구현하는 문제

현재 점유중인 손님의 time quantum이 종료됨과 동시에 손님이 들어왔을 때 처리가 잘못 된 것인지 .. 계속 틀렸다 ㅠ

 

1주 4문제 실천중인데.. 1일 1문제 풀어야 하나 ❓❓ ㅎㅎ

코딩하기 정말 힘들다 ~~

#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

typedef struct {
	int p, t;
}customer;
typedef struct {
	int p, t, c;
}waiting;
typedef struct {
	bool operator()(waiting a, waiting b) {
		return a.c > b.c;
	}
}cmp;

int N, T, W, M;
queue<customer> c;
priority_queue<waiting, vector<waiting>, cmp> w;

int main() {
	scanf("%d%d%d", &N, &T, &W);
	for (int i = 0, p, t; i < N; i++) {
		scanf("%d%d", &p, &t);
		c.push({ p,t });
	}
	scanf("%d", &M);
	for (int i = 0, p, t, c; i < M; i++) {
		scanf("%d%d%d", &p, &t, &c);
		w.push({ p,t,c });
	}

	int time = 0;
	while (time < W) {
		auto cur = c.front(); c.pop();

		for (int t = 0; t < min(cur.t, T); t++) {
			if (time >= W)break;
			printf("%d\n", cur.p);
			time++;
		}
		if (time >= W)break;

		while (!w.empty() && w.top().c <= time) {
			c.push({ w.top().p,w.top().t });
			w.pop();
		}
		if (cur.t > T) {
			c.push({ cur.p,cur.t - T });
		}
	}
	return 0;
}