#3RE

P1618 三连击(升级版)

qwertyuuiigfvcgv @ 2024-01-04 17:34:22

#include<iostream>
#include<vector>
#include<sstream>
#include<stdio.h>
using namespace std;
int a[4];
int ans[32767][4];
int x = 0;
bool check[4];
void dfs(int k,int a1,int b,int c){
    if(k>=3){
        int ans1 = 0;
        for(int i = 0;i<3;i++){
            ans1 = ans1*10+a[i];
        }
        vector<bool> c1;
        for(int i = 0;i<=10;i++){
            c1.push_back(false);
        }
        c1[a[0]] = true;
        c1[a[1]] = true;
        c1[a[2]] = true;
        if(ans1%a1 == 0){
            int gb = ans1/a1;
            if(gb*b<=999&&gb*c<=999){
                int b1 = gb*b;
                int c2 = gb*c;
                stringstream s1;
                stringstream s2;
                s1<<b1;
                s2<<c2;
                string sb1 = s1.str();
                string sc2 = s2.str();
                bool has=  false;
                for(int i = 0;i<3;i++){
                    if(sb1[i] == '0'){
                        has = true;
                        break;
                    }
                    if(c1[sb1[i] - '0']){
                        has = true;
                        break;
                    }else{
                        c1[sb1[i] - '0'] = true;
                    }
                }
                if(!has){
                    has = false;
                    for(int i = 0;i<3;i++){
                        if(sc2[i] == '0'){
                            has = true;
                            break;
                        }
                        if(c1[sc2[i] - '0']){
                            has = true;
                            break;
                        }else{
                            c1[sc2[i] - '0'] = true;
                        }
                    }
                    if(!has){
                        ans[x][0] = ans1;
                        ans[x][1] = gb*b;
                        ans[x][2] = gb*c;
                        x++;
                    }
                }
            }
        }
        return;
    }
    for(int i = 1;i<=9;i++){
        if(!check[i]){
            a[k] = i;
            check[i] = true;
            dfs(k+1,a1,b,c);
            check[i] = false;
        }

    }
}
int main(){
    //freopen("C:\\Users\\Lilebin\\Downloads\\P1618_3.in","r",stdin);
    int a1,b,c;
    cin>>a1>>b>>c;
    if(a1 == 0||b==0||c==0){
        cout<<"No!!!";
        return 0;
    }
    dfs(0,a1,b,c);
    if(x==0){
        cout<<"No!!!";
    }else{
        for(int i = 0;i<x;i++){
            cout<<ans[i][0]<<" "<<ans[i][1]<<" "<<ans[i][2]<<endl;
        }
    }
}

3RE

过数据点无问题,请问问题出在哪?


by jiadahao @ 2024-01-28 19:49:52

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

int a,b,c,n,f;

bool zi(int x,int y,int z){
    int a[10];
    a[1]=x%10;
    a[2]=x/10%10;
    a[3]=x/100%10;
    a[4]=y%10;
    a[5]=y/10%10;
    a[6]=y/100%10;
    a[7]=z%10;
    a[8]=z/10%10;
    a[9]=z/100%10;
    sort(a+1,a+10);
    for(int i=1;i<=9;i++){
        if(a[i]!=i)return 0;
    }   
    return 1;
}

int main(){
    scanf("%d%d%d",&a,&b,&c);
    double x=b/(a*1.0),y=c/(a*1.0);
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            for(int k=1;k<=9;k++){
                n=i*100+j*10+k;
                if(i!=j&&j!=k&&i!=k){
                    int a1=n*x,a2=n*y;
                    if(zi(n,a1,a2)&&n<1000&&a1<1000&a2<1000){
                        cout<<n<<" "<<a1<<" "<<a2<<endl;
                        f=1;
                    }
                }
            }   
        }   
    }
    if(f==0){
        cout<<"No!!!";
    }
    return 0;
}

这个我自己写的,先三个循环枚举出第一个数,再用比例求出二三个数,大大节约时间了,然后判断是否超出1000,是否是1~9(自定义函数),就AC了 大佬们别喷行吧。。。


|