728x90
반응형
[24번 문제]
어떤 대상을 순서에 따라 배열한 것을 순열이라고 합니다. 예를 들어 3124는 숫자 1, 2, 3, 4로 만들 수 있는 순열 중 하나입니다.
이렇게 만들 수 있는 모든 순열을 숫자나 문자 순으로 늘어놓은 것을 사전식(lexicographic) 순서라고 합니다.
0, 1, 2로 만들 수 있는 사전식 순열은 다음과 같습니다.
012 021 102 120 201 210
0, 1, 2, 3, 4, 5, 6, 7, 8, 9로 만들 수 있는 사전식 순열에서 1,000,000번째는 무엇입니까?
[코드]
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 | #include "stdafx.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; long ans = 0; int main() { vector <int> list; int temp = 0; for (int i = 0; i < 10; i++) list.push_back(i); while (temp != 999999) { next_permutation(list.begin(), list.end()); temp++; } for (int i = 0; i < 10; i++) cout << list.at(i); cout<< endl; system("pause"); return 0; } | cs |
728x90
반응형