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 | 29 | 30 | 31 |
Tags
- TObjectPtr
- 프로그래머스
- Unreal Engine5
- Frustum
- softeer
- DirectX11
- IFileDialog
- UnrealEngine5
- NRVO
- GeeksForGeeks
- 1563
- RootMotion
- const
- 언리얼엔진5
- 오블완
- 백준
- winapi
- 줄 세우기
- 팰린드롬 만들기
- algorithm
- UnrealEngine4
- RVO
- C++
- 2294
- C
- baekjoon
- directx
- UE5
- 티스토리챌린지
- Programmers
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 1174번 :: 줄어드는 수 본문
https://www.acmicpc.net/problem/1174
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_set>
#include <thread>
#include <atomic>
using namespace std;
int n;
vector<long long> answer;
void DFS(string num)
{
answer.push_back(stoll(num));
int endNum = num.back() - '0';
for (int i = endNum - 1; i >= 0; --i)
{
num.push_back(i + '0');
DFS(num);
num.pop_back();
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 9; i >= 0; --i)
{
string temp = "";
DFS(temp += i + '0');
}
sort(answer.begin(), answer.end());
if (n >= 1024) cout << -1;
else cout << answer[n - 1];
}
|
cs |
어떤 규칙으로 해야 정확한 순번으로 저장할 수 있을까.. 고민 좀 했었는데, 그냥 어떤 방식이든 줄어드는 수를 구한다음에 오름차순정렬을 해주면 된다는 걸 깨달았다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm]Baekjoon 1507번 :: 궁금한 민호 (0) | 2025.03.17 |
---|---|
[Algorithm]Baekjoon 10819번 :: 차이를 최대로 (0) | 2025.03.17 |
[Algorithm]Baekjoon 1939번 :: 중량제한 (0) | 2025.03.17 |
[Algorithm]Baekjoon 3020번 :: 개똥벌레 (0) | 2025.03.17 |
[Algorithm]Baekjoon 2352번 :: 반도체 설계 (0) | 2025.03.17 |