티스토리 뷰


문제가 좀 길다

요약하자면 X진법으로 나타낸 수 A와 Y진법으로 나타낸 수 B를 줄 때

A=B를 만드는 X와 Y를 찾는 문제다


예를들어 A = 419 // B = 782를 줬을 때

8892 를 47진법으로 나타내면 419 , 35진법으로 나타내면 782 이므로

답은 X=47, Y=35 이다


문제는 길지만 수가 작아서 쉽다

완탐으로 진짜 다 해보면 된다~!


소스코드

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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long    
vector<pair<ll, pair<ll,ll>>> vt;
 
ll go(ll a, ll b) {
    ll ret = 0;
    ll c = 1;
    while (a != 0) {
        ret += (a % 10)*c;
        a /= 10; c *= b;
    }
    return ret;
}
int main() {
    ll n, a, b;
    scanf(" %lld"&n);
    while (n--) {
        vt.clear();
        scanf(" %lld %lld"&a, &b);
        for (ll i = 10; i <= 15000; i++) {
            vt.push_back({ go(a,i),{i,-1} });
            vt.push_back({ go(b,i),{i,1} });
        }
        sort(vt.begin(), vt.end());
        for (int i = 0; i < vt.size()-1; i++) {
            if (vt[i].first == vt[i + 1].first) {
                ll x = vt[i].second.second == -1 ? vt[i].second.first : vt[i + 1].second.first;
                ll y = vt[i + 1].second.second == 1 ? vt[i + 1].second.first : vt[i].second.first;
                printf("%lld %lld\n", x, y); break;
            }
        }
    }
}
cs


'알고리즘 > BOJ' 카테고리의 다른 글

[백준] 10747 Censoring  (0) 2018.06.30
[백준] 10678 Meeting Time  (0) 2018.06.29
[백준] 10748 Cow Hopscotch  (0) 2018.06.29
[백준] 10750 Censoring  (0) 2018.06.28
[백준] 13264 접미사 배열2  (4) 2018.06.27
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
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
글 보관함