※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 10104번 문제인 Party Invitation이다.
문제는 아래 링크를 확인하자.

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

 

10104번: Party Invitation

The first line of input contains the integer K (1 ≤ K ≤ 100). The second line of input contains the integer m (1 ≤ m ≤ 10), which is the number of rounds of removal. The next m lines each contain one integer. The ith of these lines (1 ≤ i ≤ m)

www.acmicpc.net

1부터 K까지 채워넣은 벡터를 준비하자.

 

그 이후, 매 차례마다 준비한 벡터의 r번째 원소를 제외한 모든 원소를 집어넣은 새 벡터를 만들어 기존 벡터를 새 벡터로 갱신하는 것을 반복하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int N, M;
vector<int> cur, nxt;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M;
	for (int i = 1; i <= N; i++) cur.emplace_back(i);

	while (M--) {
		int r; cin >> r;
		int cursize = cur.size();
		for (int i = 0; i < cursize; i++) {
			if ((i + 1) % r == 0) continue;
			nxt.emplace_back(cur[i]);
		}

		swap(cur, nxt);
		nxt.clear();
	}

	for (auto& x : cur) cout << x << '\n';
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 20017 // C++] Топот котов  (0) 2022.11.24
[BOJ 13216 // C++] Badminton  (0) 2022.11.24
[BOJ 15477 // C++] 水ようかん (Mizuyokan)  (0) 2022.11.24
[BOJ 25400 // C++] 제자리  (0) 2022.11.24
[BOJ 15238 // C++] Pirates  (0) 2022.11.24

+ Recent posts