숫자가 많아도 작은 순으로 4개만 있으면 무조건 최소가 되는 조합이 나온다.


4C2를 다 만들고 sort하면 된다.


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
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
 
int n, t, a[] = { 0,10,100,1000,10000 };
priority_queue<int> q;
vector<int> v, ans;
 
int rad(int x) {
    int cn = 0;
    while (x > 0) x /= 10, cn++;
    return cn;
}
 
int main() {
    scanf("%d"&n);
    while (n--) {
        scanf("%d"&t);
        q.push(t);
        if (q.size() > 4) q.pop();
    }
    while (q.size()) v.push_back(q.top()), q.pop();
    for (int i = 0; i < v.size(); i++for (int j = i + 1; j < v.size(); j++) {
        ans.push_back(v[i] * a[rad(v[j])] + v[j]);
        ans.push_back(v[j] * a[rad(v[i])] + v[i]);
    }
    sort(ans.begin(), ans.end());
    printf("%d", ans[2]);
    return 0;
}
cs


'BOJ' 카테고리의 다른 글

12835 삼거리  (0) 2017.10.30
3159 전구  (0) 2017.10.30
3758 KCPC  (0) 2017.10.30
1898 이전 수열은 어떤 수열일까  (0) 2017.10.30
13226 Divisors Again  (0) 2017.10.30

+ Recent posts