UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213281#3847. 分数约分1811260623103196ms1264kbC++112.4kb2024-11-10 11:36:122024-11-10 13:05:48

answer

#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int t, a, b, n, gcdd, minn, minx, shu[11], shuu[11], nowshu[11], nowshuu[11];
string s, ss;
bool xuan[21];
int stolll(string s)
{
    int res = 0;
    for (int i = 0; i < s.size(); i++)
    {
        res = res * 10 + s[i] - '0';
    }
    return res;
}
void dfs(int x)
{
    if (x == n)
    {
        string res = "";
        memset(nowshu, 0, sizeof(nowshu));
        memset(nowshuu, 0, sizeof(nowshuu));
        for (int i = 0; i < n; i++)
        {
            if (xuan[i])
            {
                res += s[i];
                nowshu[s[i] - '0']++;
            }
        }
        int num = stolll(res);
        if (num == 0)
            return;
        if (a * b % num != 0)
            return;
        num = b * num / a;
        string res2 = to_string(num);
        //cout << res << "/" << res2 << ' ' << a << '/' << b << endl;
        for (int i = 0; i < res2.size(); i++)
        {
            nowshuu[res2[i] - '0']++;
        }
        for (int i = 0; i < 10; i++)
        {
            //cout<<shu[i]-nowshu[i]<<' '<<shuu[i]-nowshuu[i]<<endl;
            if (shu[i] - nowshu[i] < 0 || shuu[i] < nowshuu[i])
            {
                return;
            }
            if (shu[i] - nowshu[i] != shuu[i] - nowshuu[i])
            {
                return;
            }
        }
        int ans1 = stolll(res);
        int ans2 = stolll(res2);
        if (ans1 * b == a * ans2)
        {
            minn = min(minn, ans1);
            minx = min(minx, ans2);
        }
        return;
    }
    xuan[x] = true;
    dfs(x + 1);
    xuan[x] = false;
    dfs(x + 1);
}
signed main()
{
    scanf("%lld", &t);
    while (t--)
    {
        scanf("%lld %lld", &a, &b);
        memset(xuan, 0, sizeof(xuan));
        memset(shu, 0, sizeof(shu));
        memset(shuu, 0, sizeof(shuu));
        bool flag = false;
        if (a > b)
        {
            flag = true;
            swap(a, b);
        }
        minn = a, minx = b;
        s = to_string(a);
        ss = to_string(b);
        for (int i = 0; i < s.size(); i++)
        {
            shu[s[i] - '0']++;
            shuu[ss[i] - '0']++;
        }
        n = s.size();
        dfs(0);
        if (!flag)
            printf("%lld %lld\n", minn, minx);
        else
            printf("%lld %lld\n", minx, minn);
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1260kb

input:

10
295227892 738069730
21284157 63852471
312774536 781936340
82221828 68518190
167752458 55917486
90...

output:

295227892 738069730
21284157 63852471
312774536 781936340
82221828 68518190
167752458 55917486
90674...

result:

wrong answer 3rd numbers differ - expected: '21', found: '21284157'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 1260kb

input:

10
7231248 1807812
4301415 3441132
1931046 3862092
5184264 3240165
1144774 1717161
298584 2388672
87...

output:

324 81
4301415 3441132
114 228
48 30
1144774 1717161
298584 2388672
878981 7910829
370928 2967424
14...

result:

wrong answer 5th numbers differ - expected: '193146', found: '114'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 1260kb

input:

10
72320000 27120000
110000 11000000
90100000 9010000
270000 75600000
8230000 82300000
17910000 5970...

output:

32 12
110000 11000000
10 1
270000 75600000
8230000 82300000
17910000 5970000
8930000 940000
90 9
798...

result:

wrong answer 3rd numbers differ - expected: '1', found: '110000'

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 1256kb

input:

10
6700512 10050768
6712050 10068075
7172058 10758087
9318720 13978080
71635224 107452836
71643522 1...

output:

6700512 10050768
6712050 10068075
7172058 10758087
12 18
71635224 107452836
71643522 107465283
71992...

result:

wrong answer 1st numbers differ - expected: '670512', found: '6700512'

Test #5:

score: 0
Wrong Answer
time: 350ms
memory: 1260kb

input:

10
44896548685746979 44896548685746979
76555658957975878 76555658957975878
9999998899899899 99999988...

output:

44896548685746979 44896548685746979
5 5
9 9
66866776659978777 66866776659978777
2 2
9 9
989898888898...

result:

wrong answer 1st numbers differ - expected: '4', found: '44896548685746979'

Test #6:

score: 0
Wrong Answer
time: 346ms
memory: 1256kb

input:

10
5586978859946748 5586978859946748
5875932326322532 5875932326322532
7877997999879887 787799799987...

output:

4 4
2 2
97 97
99999999999999999 99999999999999999
4 4
8 8
8 8
8689979595794777 8689979595794777
7777...

result:

wrong answer 5th numbers differ - expected: '7', found: '97'

Test #7:

score: 0
Wrong Answer
time: 268ms
memory: 1256kb

input:

10
163163163163163 326326326326326
163163111163111 326326222326222
142847142847 285714285714
2857142...

output:

163163163163163 326326326326326
163163111163111 326326222326222
142847142847 285714285714
2857142857...

result:

wrong answer 1st numbers differ - expected: '11111', found: '163163163163163'

Test #8:

score: 0
Wrong Answer
time: 996ms
memory: 1256kb

input:

10
142847114287112857 285714228574225714
142847111111112857 285714222222225714
142847111111111111 28...

output:

142847114287112857 285714228574225714
142847111111112857 285714222222225714
142847111111111111 28571...

result:

wrong answer 7th numbers differ - expected: '11111111111111111', found: '111111111111111110'

Test #9:

score: 0
Wrong Answer
time: 419ms
memory: 1256kb

input:

10
687069149440626451 336182506802090732
216198376277246428 246457923661369649
43706817238884428 372...

output:

687069149440626451 336182506802090732
216198376277246428 246457923661369649
43706817238884428 372089...

result:

wrong answer 11th numbers differ - expected: '11111', found: '163163163163163'

Test #10:

score: 0
Wrong Answer
time: 815ms
memory: 1264kb

input:

10
142847114247112857 285714228714225714
142847111111112857 285714222222225714
142847111111111111 28...

output:

142847114247112857 285714228714225714
142847111111112857 285714222222225714
142847111111111111 28571...

result:

wrong answer 7th numbers differ - expected: '11111111111111111', found: '111111111111111110'