1138 한 줄로 서기
2019. 8. 2. 11:22ㆍ알고리즘/백준
키 작은 사람부터 채워야만 그리디하게 해결할 수 있다
문제: https://www.acmicpc.net/problem/1138
깃허브주소: https://github.com/surinoel/boj/blob/master/1138.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int a[11]; | |
int b[11]; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
for (int i = 1; i <= n; i++) { | |
cin >> a[i]; | |
} | |
for (int i = 1; i <= n; i++) { | |
int cnt = 0; | |
for (int j = 1; j <= n; j++) { | |
if (b[j] == 0) { | |
cnt += 1; | |
} | |
if (cnt > a[i]) { | |
b[j] = i; | |
break; | |
} | |
} | |
} | |
for (int i = 1; i <= n; i++) { | |
cout << b[i] << ' '; | |
} | |
cout << '\n'; | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
3023 마술사 이민혁 (0) | 2019.08.04 |
---|---|
10174 펠린드롬 (0) | 2019.08.03 |
1236 성 지키기 (0) | 2019.08.01 |
1543 문서 검색 (0) | 2019.08.01 |
17363 우유가 넘어지면? (0) | 2019.07.31 |