-
[C++] ์ผ์ฑ 2477. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์ฐจ๋ ์ ๋น์์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:18728x90
์ ์ ์ฐฝ๊ตฌ์ ์ ๋น ์ฐฝ๊ตฌ์ ์๋์ ๊ตฌํํ๋ค.
์ ์ ์ฐฝ๊ตฌ๊ฐ ๋น์ด์๋ค๋ฉด ์ฐจ๋ก๋๋ก ๊ณ ๊ฐ์ ๋ฃ์ด์ค๋ค.
์ ์ ์ฐฝ๊ตฌ์์ ์ผ์ด ๋๋ ๊ณ ๊ฐ์ ์ ๋น ์ฐฝ๊ตฌ๋ก ๋ฐ๋ก ์ด๋ํ๋ค. ์ ๋น ์ฐฝ๊ตฌ๊ฐ ๊ฝ ์ฐจ์์ผ๋ฉด ๊ธฐ๋ค๋ฆฐ๋ค.
๊ฐ์ฅ ๋ฆ๊ฒ ๋์ฐฉํ ๊ณ ๊ฐ์ ์๊ฐ๋ณด๋ค ์ง๋ ์๊ฐ์ ํด ๊ฒฝ์ฐ, ์ ์ ์ฐฝ๊ตฌ์ ์ ๋น ์ฐฝ๊ตฌ๊ฐ ๋ชจ๋ ๋น์ด์๋ค๋ฉด ์๋์ ๋ฉ์ถ๋ค.
#include <iostream> #include <queue> #include <cstring> using namespace std; struct INF { int client_num, time; }; struct Client { int rec, rep, arr_time; } client[1001]; INF reception[10], repair[10]; int rec_time[10], rep_time[10]; int N, M, K, A, B; void process_work() { memset(reception, 0, sizeof(reception)); memset(repair, 0, sizeof(repair)); queue<int> rep_wait; int time = 0; int index = 1; while (1) { for (int i = 1; i <= N; i++) { if (reception[i].time > 0) { reception[i].time--; if (reception[i].time == 0) { rep_wait.push(reception[i].client_num); reception[i].client_num = 0; } } } while (index <= K and client[index].arr_time <= time) { bool flag = false; for (int i = 1; i <= N; i++) { if (reception[i].time == 0) { reception[i].time = rec_time[i]; reception[i].client_num = index; client[index++].rec = i; flag = true; break; } } if (!flag) break; } for (int i = 1; i <= M; i++) { if (repair[i].time > 0) { repair[i].time--; } } while (!rep_wait.empty()) { bool flag = false; for (int i = 1; i <= M; i++) { if (repair[i].time == 0) { int now = rep_wait.front(); rep_wait.pop(); repair[i].time = rep_time[i]; client[now].rep = i; flag = true; break; } } if (!flag) break; } time++; if (time > client[K].arr_time) { int cnt = 0; for (int i = 1; i <= N; i++) { if (reception[i].time == 0) cnt++; } for (int i = 1; i <= M; i++) { if (repair[i].time == 0) cnt++; } if (cnt == N + M) break; } } } int get_client_num() { int ret = -1; for (int i = 1; i <= K; i++) { if (client[i].rec == A and client[i].rep == B) { if (ret == -1) ret = 0; ret += i; } } return ret; } int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { cin >> N >> M >> K >> A >> B; for (int i = 1; i <= N; i++) cin >> rec_time[i]; for (int i = 1; i <= M; i++) cin >> rep_time[i]; for (int i = 1; i <= K; i++) cin >> client[i].arr_time; process_work(); cout << '#' << t << ' ' << get_client_num() << endl; } return 0; }
728x90'์ฝ๋ฉํ ์คํธ > ์ฝ๋ฉํ ์คํธ ์ฐ์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++] ์ผ์ฑ 1249. [S/W ๋ฌธ์ ํด๊ฒฐ ์์ฉ] 4์ผ์ฐจ - ๋ณด๊ธ๋ก (0) 2020.10.27 [C++] [ํ๋ก๊ทธ๋๋จธ์ค 2020 KAKAO] ๊ธฐ๋ฅ๊ณผ ๋ณด ์ค์น (0) 2020.10.27 [C++] ๋ฐฑ์ค 1389๋ฒ. ์ผ๋น ๋ฒ ์ด์ปจ์ 6๋จ๊ณ ๋ฒ์น (0) 2020.10.27 [C++] ์ผ์ฑ 4014. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ํ์ฃผ๋ก ๊ฑด์ค (0) 2020.10.27 [C++] ๋ฐฑ์ค 9372๋ฒ. ์๊ทผ์ด์ ์ฌํ (0) 2020.10.27