본문 바로가기
Programming/Algorithm

swexpert 차량정비소

by OKOK 2018. 3. 5.

/*

1322 차량 정비소

1455


2:30 2시간 30분ㄴ


t1, 접수대1,2 정비소1,2 t2 이렇게 총 6가지 장소가 있습니다.

그리고 1번의 사람은 어디어디에서 받았는지 기록하는 것 추가요.


먼저 t1에 대기를 시켜둡니다.

그리고 먼저 온 사람부터 빠져나가므로 queue 형태가 맞습니다.

그리고 

접수대에 위치하는 사람을 저장하는 장소를 만듭니다.

접수대 1,2, 3.... 이상이 될 것 같은데 자료 구조를 어떻게 사용하지?

접수대에는 사람넘버와 들어온 시간, 접수대에서 소요되는 시간을 계산하면 됩니다.


처음 시간을 보면


1 은 1,2 를 저장하면 됩니다. 

2 는

3 은

4 는

5 는

*/


#include <iostream>

#include <queue>

#include <algorithm>

using namespace std;


int N, M, K, A, B;

int ans;

int a[10], b[10];

int tk[1001];

int t = 0;

struct points {

int x, y;

};

points log_store[1001];


queue<int> t1, t2, waiting_1, waiting_2;

struct in {

int num;

int w;

};

in recep[10], repair[10];


void problemIn() {

cin >> N >> M >> K >> A >> B;

for (int i = 0; i < N; i++) {

cin >> a[i];

}

for (int i = 0; i < M; i++) {

cin >> b[i];

}

for (int i = 0; i < K; i++) {

cin >> tk[i];

}

}


void init() {

for (int i = 0; i < N; i++)

a[i] = 0;

for (int i = 0; i < M; i++)

b[i] = 0;

for (int i = 0; i < K; i++)

tk[i] = 0;

for (int i = 1; i <= K; i++) {

log_store[i].x = 0;

log_store[i].y = 0;

}

queue<int> empty;

swap(t2, empty);

ans = t = 0;

}

/*

먼저 하나에 대해서 풀어보도록 하겠습니다.

t waiting_1 recep[0]

0 1 1.3

1 1.2

2 1.1

3


i 는 몇번을 돌려야하는 것이지? 


0 0 1 2 3 4

*/

// tk -> t1 -> waiting_1 -> recep 1,2  -> w-- -> waiting_2 -> repair 1,2 -> w-- -> t2

void solve() {


while (1) {

// tk -> waiting_1

for (int i = 0; i<K; i++) {

if (tk[i] == t) {

waiting_1.push(i+1);

}

}


// recep1,2 -> waiting_2

for (int i = 0; i < N; i++) {

if (recep[i].num > 0) {

if (recep[i].w == 0) {

waiting_2.push({ recep[i].num });

recep[i].num = 0;

}

}

}


// repair1,2 -> t2

for (int i = 0; i < N; i++) {

if (repair[i].num > 0) {

if (repair[i].w == 0) {

t2.push({ repair[i].num });

repair[i].num = 0;

}

}

}


// waiting_1 -> recep1,2

for (int i = 0; i < N; i++) {

if (!waiting_1.empty()) {

if (recep[i].num == 0) {

recep[i].num = waiting_1.front();

recep[i].w = a[i];

log_store[recep[i].num].x = i + 1;

waiting_1.pop();

}

}

}


// recep1,2 w--

for (int i = 0; i < N; i++) {

if (recep[i].num > 0) {

if (recep[i].w > 0) {

recep[i].w -= 1;

}

}

}


// waiting_2 -> repair 1,2

for (int i = 0; i < M; i++) {

if (!waiting_2.empty()) {

if (repair[i].num == 0) {

repair[i].num = waiting_2.front();

repair[i].w = b[i];

log_store[repair[i].num].y = i + 1;

waiting_2.pop();

}

}

}


// repair1,2 w--

for (int i = 0; i < M; i++) {

if (repair[i].num > 0) {

if (repair[i].w > 0) {

repair[i].w -= 1;

}

}

}


t++;

if (t2.size() == K) break;

}

}


void check() {

for (int i = 1; i <= K; i++) {

if (log_store[i].x == A && log_store[i].y == B) {

ans += i;

}

}

}


/*

1 1 2 1 1



*/

int main() {

int T;

cin >> T;

for (int tc = 1; tc <= T; tc++) {

problemIn();


solve();

check();

if (ans == 0) ans = -1;

cout << "#" << tc << " " << ans << endl;

init();

}

return 0;

}


/*

4 1 10 3 1

4 6 4 8

1

0 3 4 4 5 6 9 9 9 10

*/ 


차량정비소, 구조체를 잘 사용해야 하며, 처음 설계할 때 어떻게 할 것인지 명확히 합니다. 그리고 문제가 긴 문제는 2번 3번 읽어서 어떻게 작동이 하는지 명확하게 안다음에, 초를 기준으로 획을 긋도록 합니다. 그리고 어디가 선행인지 어디가 후행인지 이런것들을 명확히 한다음에 풀이하도록 합니다.