Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 재귀
- 그래프
- 자료구조
- 문자열
- 시뮬레이션
- 유니온 파인드
- 알고리즘
- 투 포인터
- 트리
- 수학
- Unreal Engine 5
- 스택
- 우선순위 큐
- 유니티
- 다익스트라
- 백준
- 다이나믹 프로그래밍
- 그리디 알고리즘
- ue5
- 구현
- VR
- 백트래킹
- BFS
- 정렬
- 누적 합
- XR Interaction Toolkit
- Team Fortress 2
- DFS
- c++
- 브루트포스
Archives
- Today
- Total
1일1알
백준 17298번 오큰수 C++ 본문
스택을 쌓으면서 자기보다 큰 수를 만나면 pop하면서 전에 있는 수들까지 검사하는 식으로 문제를 풀었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> arr(n);
vector<int> ans(n, -1);
stack<int> st;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
while (!st.empty() && arr[st.top()] < arr[i]) {
ans[st.top()] = arr[i];
st.pop();
}
st.push(i);
}
for (auto a : ans) {
cout << a << " ";
}
};
'알고리즘' 카테고리의 다른 글
백준 1158번 요세푸스 문제 C++ (0) | 2022.06.02 |
---|---|
백준 10799번 쇠막대기 C++ (0) | 2022.06.01 |
백준 2573번 빙산 C++ (0) | 2022.05.30 |
백준 2644번 촌수계산 C++ (0) | 2022.05.29 |
백준 1189번 컴백홈 C++ (0) | 2022.05.28 |