※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 3280번 문제인 CARDS이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/3280
3280번: CARDS
To the first and only line of output file should be written all the numbers from the smallest set of numbers that are candidates for Hal’s number. The numbers can be written in any order, and must be separated by a space.
www.acmicpc.net
입력으로 주어지는 카드의 수가 1000장이 안 되고 카드를 펼쳐 몇 열에 있는지 지목하는 횟수 또한 10회 이하로 적으므로, 일어나는 일을 직접 시뮬레이션하는 코드를 작성해 문제를 해결할 수 있다.
글쓴이는 큐(queue) 자료구조와, 각 수가 여전히 후보인지를 나타내는 bool 변수를 수와 함께 기록하기 위한 pair을 이용해 문제에 주어진 과정을 시뮬레이션하는 구현하였다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int N, D;
queue<pair<int, bool>> que;
pair<int, bool> arr[333][3];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N; N /= 3;
for (int i = 0; i < N; i++) {
que.push(make_pair(3 * i + 1, 1));
que.push(make_pair(3 * i + 2, 1));
que.push(make_pair(3 * i + 3, 1));
}
cin >> D;
while (D--) {
for (int r = 0; r < N; r++) {
for (int c = 0; c < 3; c++) {
arr[r][c] = que.front();
que.pop();
}
}
string s; cin >> s;
if (s != "first") {
for (int r = 0; r < N; r++) arr[r][0].second = 0;
}
if (s != "second") {
for (int r = 0; r < N; r++) arr[r][1].second = 0;
}
if (s != "third") {
for (int r = 0; r < N; r++) arr[r][2].second = 0;
}
for (int c = 0; c < 3; c++) {
for (int r = 0; r < N; r++) {
que.push(arr[r][c]);
}
}
}
while (!que.empty()) {
if (que.front().second) cout << que.front().first << ' ';
que.pop();
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 27251 // C++] Звездочки (0) | 2023.01.17 |
---|---|
[BOJ 23321 // C++] 홍익 댄스파티 (0) | 2023.01.16 |
[BOJ 3276 // C++] ICONS (0) | 2023.01.16 |
[BOJ 3281 // C++] T9 (0) | 2023.01.15 |
[BOJ 3282 // C++] ROOMS (0) | 2023.01.15 |