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
- 다이나믹 프로그래밍
- 그래프
- DFS
- 다익스트라
- ue5
- 트리
- BFS
- 누적 합
- 스택
- c++
- 백트래킹
- 백준
- 투 포인터
- VR
- 유니온 파인드
- 시뮬레이션
- 브루트포스
- 문자열
- 재귀
- 우선순위 큐
- Unreal Engine 5
- XR Interaction Toolkit
- 정렬
- 그리디 알고리즘
- Team Fortress 2
- 수학
- 유니티
- 알고리즘
- 구현
- 자료구조
Archives
- Today
- Total
1일1알
백준 10972번 다음 순열 C++ 본문
https://www.acmicpc.net/problem/10972
10972번: 다음 순열
첫째 줄에 입력으로 주어진 순열의 다음에 오는 순열을 출력한다. 만약, 사전순으로 마지막에 오는 순열인 경우에는 -1을 출력한다.
www.acmicpc.net
stl의 next_permutation을 사용하면 쉽게 풀 수 있다.
#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 <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<int>(n);
for (int i = 0; i < n; i++) cin >> v[i];
if (next_permutation(v.begin(), v.end())) {
for (auto a : v) {
cout << a << " ";
}
}
else cout << -1;
}
'알고리즘' 카테고리의 다른 글
백준 15664번 N과 M(10) C++ (0) | 2023.05.30 |
---|---|
백준 20365번 블로그2 C++ (0) | 2023.05.29 |
백준 19942번 다이어트 C++ (0) | 2023.05.27 |
백준 14675번 단절점과 단절선 C++ (0) | 2023.05.26 |
백준 21938번 영상처리 C++ (0) | 2023.05.25 |