#include <iostream> #include <vector> using namespace std; vector<pair<int, int> > v; bool isDeleted[1001]; int n; int main() { scanf("%d",&n); for(int i=0;i<n;i++) { int temp; scanf("%d",&temp); v.push_back(make_pair(temp,i+1)); } int pos = 0; while(1) { printf("%d ",v[pos].second); int haveToGo = v[pos].first; isDeleted[pos] = true; int flag = 0; for(int i=0;i<n;i++) if(!isDeleted[i]) flag = 1; if(!flag) break; if(haveToGo > 0) { while(haveToGo != 0) { haveToGo--; pos++; if(pos >= n) pos = 0; if(isDeleted[pos]) { haveToGo++; continue; } } } else if(haveToGo < 0) { while(haveToGo != 0) { haveToGo++; pos--; if(pos < 0) pos = n-1; if(isDeleted[pos]) { haveToGo--; continue; } } } } }
vector를 이용해 움직일 거리와 index를 삽입하고 isDeleted를 이용해 풍선이 터졌는지 안터졌는지 체크하며 이동시키는 과정을 구현했습니다. flag로 모든 풍선이 터지면 while문을 빠져나오게끔 하였습니다.
'Algorithm > Baekjoon & Algospot' 카테고리의 다른 글
[C++] BOJ 2178 - 미로 탐색 (0) | 2018.03.28 |
---|---|
[C++]BOJ 1157 - 단어 공부 (0) | 2018.03.23 |
[C++] BOJ 1182 - 부분집합의 합 (0) | 2018.03.20 |
[C++] BOJ 1260 - DFS와 BFS (0) | 2018.03.09 |
[C++] BOJ 2163 - 초콜릿 자르기 (0) | 2018.03.04 |