728x90
https://www.acmicpc.net/problem/2346
2346번: 풍선 터뜨리기
첫째 줄에 자연수 N(1≤N≤1,000)이 주어진다. 다음 줄에는 차례로 각 풍선 안의 종이에 적혀 있는 수가 주어진다. 편의상 0은 적혀있지 않다고 가정하자.
www.acmicpc.net
메인아이디어
모듈로연산을 이용한 index범위내 탐색 (원형큐)
막혔던 부분
코드에 문제가 없었으나 계속해서 틀린답으로 채점되었다. 혹시나 해서 scanf 를 cin으로 바꿨더니 바로 컴파일이 가능...
깨달은 점
vector의 make_pair를 이용하여 만들 수 있다.
scanf와 cin을 병행해서 사용하면 백준에서는 틀린답으로 내는 경우가 있으니 굳이 그러지 말아야 한다. (이유는 잘 모르겠는데 ㅠ)
참고한 (서리해낸) 답안지 블로그
https://vipeveloper.tistory.com/99
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <iostream> #include <vector> #include <cstdio> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; vector<pair<int, int>> arr; int now; int next; cin >> n; int tmp; for (int i = 0; i < n; i++) { cin >> tmp; arr.push_back(make_pair(tmp, i + 1)); } now = 0; while (arr.empty() != true) { cout << arr[now].second; next = arr[now].first; if (next > 0) { next -= 1; } arr.erase(arr.begin() + now); now += next; n--; if (n <= 0) break; now = (now >= 0 ? now : n + now % n); now %= n; cout << " "; } return 0; } | cs |
'프로그래밍 > programmers&bj' 카테고리의 다른 글
[C++][알고리즘] 프로그래머스:: 예산 (0) | 2019.09.10 |
---|---|
[C++][알고리즘] 백준 1813번 마지막한마디 (0) | 2019.09.01 |
[C++][알고리즘] 백준 14215번 볼링점수계산 (0) | 2019.08.28 |
[C++][알고리즘] 프로그래머스::타깃넘버 (0) | 2019.08.24 |
[C++][알고리즘] 프로그래머스::전화 번호 목록 (0) | 2019.08.20 |