ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213297 | #3847. 分数约分 | lqw | 20 | 118ms | 1192kb | C++ | 1.7kb | 2024-11-10 12:49:00 | 2024-11-10 13:08:34 |
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
int gcd(int a,int b){
if(a<b)swap(a,b);
return (a==b)?a:((a%2==0)?((b%2==0)?2*gcd(a/2,b/2):gcd(a/2,b)):(b%2==0)?gcd(a,b/2):gcd(b,a-b));
}
bool check(short a[],short na,short b[],short nb,int ax,int bx){
short aax[20]={0},bbx[20]={0};
short nax=0,nbx=0;
short numa[10]={0},numb[10]={0};
while(ax){
aax[++nax]=ax%10;
ax/=10;
}
while(bx){
bbx[++nbx]=bx%10;
bx/=10;
}
while(nax>nbx){
bbx[++nbx]=0;
}
while(nbx>nax){
aax[++nax]=0;
}
int i, j;
for (i = 1, j = 1; i <= na && j <= nax; i ++ ){
if(a[i]==aax[j])j++;
else numa[a[i]]++;
}
if(j<=nax)return 0;
while(i<=na)numa[a[i++]]++;
for (i = 1, j = 1; i <= nb && j <= nbx; i ++ ){
if(b[i]==bbx[j])j++;
else numb[b[i]]++;
}
if(j<=nbx)return 0;
while(i<=nb)numb[b[i++]]++;
for (int i = 0; i < 10; i ++ ){
if(numb[i]!=numa[i])return 0;
}
return 1;
}
void solve(){
int a,b,ax,bx;
cin>>a>>b;
int g=gcd(a,b);
ax=a,bx=b;
short aa[20],bb[20],na=0,nb=0;
while(ax){
aa[++na]=ax%10;
ax/=10;
}
while(bx){
bb[++nb]=bx%10;
bx/=10;
}
a/=g,b/=g;
//cout<<na<<nb;
for(int i=1;i<=g;i++){
if(check(aa,na,bb,nb,a*i,b*i)){
cout<<a*i<<" "<<b*i<<'\n';
return;
}
}
}
signed main()
{
int T;
cin>>T;
while(T--){
solve();
}
// short a[10],b[10];
// check(a,0,b,0,12323234,222888);
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Time Limit Exceeded
input:
10 295227892 738069730 21284157 63852471 312774536 781936340 82221828 68518190 167752458 55917486 90...
output:
result:
Test #2:
score: 0
Wrong Answer
time: 118ms
memory: 1192kb
input:
10 7231248 1807812 4301415 3441132 1931046 3862092 5184264 3240165 1144774 1717161 298584 2388672 87...
output:
324 81 4301415 3441132 193146 386292 518424 324015 1144774 1717161 44144 55180
result:
wrong answer 11th numbers differ - expected: '298584', found: '44144'
Test #3:
score: 0
Time Limit Exceeded
input:
10 72320000 27120000 110000 11000000 90100000 9010000 270000 75600000 8230000 82300000 17910000 5970...
output:
32 12
result:
Test #4:
score: 0
Time Limit Exceeded
input:
10 6700512 10050768 6712050 10068075 7172058 10758087 9318720 13978080 71635224 107452836 71643522 1...
output:
result:
Test #5:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
10 44896548685746979 44896548685746979 76555658957975878 76555658957975878 9999998899899899 99999988...
output:
4 4 5 5 8 8 5 5 2 2 8 8 8 8 1 1 4 4 9 9
result:
ok 20 numbers
Test #6:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
10 5586978859946748 5586978859946748 5875932326322532 5875932326322532 7877997999879887 787799799987...
output:
4 4 2 2 7 7 9 9 4 4 6 6 8 8 4 4 7 7 4 4
result:
ok 20 numbers
Test #7:
score: 0
Time Limit Exceeded
input:
10 163163163163163 326326326326326 163163111163111 326326222326222 142847142847 285714285714 2857142...
output:
11111 22222
result:
Test #8:
score: 0
Time Limit Exceeded
input:
10 142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28571...
result:
Test #9:
score: 0
Time Limit Exceeded
input:
10 687069149440626451 336182506802090732 216198376277246428 246457923661369649 43706817238884428 372...
output:
687069149440626451 336182506802090732 216198376277246428 246457923661369649 671571742376287098 68764...
result:
Test #10:
score: 0
Time Limit Exceeded
input:
10 142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28571...