2427: 【普及-】【P1618】三连击(升级版)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:18 解决:12

题目描述

将 lns="http://www.w3.org/1998/Math/MathML">1,2,,9 共 lns="http://www.w3.org/1998/Math/MathML">9 个数分成三组,分别组成三个三位数,且使这三个三位数的比例是 lns="http://www.w3.org/1998/Math/MathML">::,试求出所有满足条件的三个三位数,若无解,输出 No!!!

输入

三个数,lns="http://www.w3.org/1998/Math/MathML">,,

输出

若干行,每行 lns="http://www.w3.org/1998/Math/MathML">3 个数字。按照每行第一个数字升序排列。

样例输入 复制

1 2 3

样例输出 复制

192 384 576
219 438 657
273 546 819
327 654 981

提示

保证 lns="http://www.w3.org/1998/Math/MathML"><<

#include<bits/stdc++.h>
using namespace std;

int b[10];
void go(int x){ //分解三位数到桶里
    b[x%10]=1;
    b[x/10%10]=1;
    b[x/100]=1;
}
bool check(int x,int y,int z){
    memset(b,0,sizeof(b));
    if(y>999||z>999) return 0;
    go(x),go(y),go(z);
    for(int i=1;i<=9;i++)
        if(!b[i])
            return 0;
    return 1;
}
int main(){
    long long A,B,C,x,y,z,cnt=0;
    cin>>A>>B>>C;
    if (A==0||B==0||C==0) {
    	puts("No!!!");
    	return 0;
	}
    for(x=123;x<=987;x++){
        if(x*B%A || x*C%A) continue;
        y=x*B/A,z=x*C/A;
        if(check(x,y,z)) {
            printf("%lld %lld% lld\n",x,y,z);
            cnt++;
        }
    }
    if(!cnt)puts("No!!!");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[10];
int main(){
	LL A,B,C,x,y,z,cnt=0;
	cin>>A>>B>>C;
    for (int i = 1; i <= 9; i++)
        a[i] = i;
    do { 
        x = a[1] * 100 + a[2] * 10 + a[3];
        y = a[4] * 100 + a[5] * 10 + a[6];
        z = a[7] * 100 + a[8] * 10 + a[9];
        if (x*B==y*A&&y*C==z*B) //避免浮点误差和爆long long的小技巧
            printf("%lld %lld %lld\n", x, y, z), cnt++;
    } while (next_permutation(a + 1, a + 10));
    if (!cnt)puts("No!!!");
    return 0;
}