玄关求助

P1618 三连击(升级版)

jaspersgr114514 @ 2024-09-22 13:37:53

#include <bits/stdc++.h>
using namespace std;
bool check(int x, int y, int z)
{
    bool use[10];
    memset(use, false, sizeof(use));
    while (x)
    {
        if (use[x % 10] == true || x % 10 == 0)
            return false;
        else
        {
            use[x % 10] = true;
            x /= 10;
        }
    }
    while (y)
    {
        if (use[y % 10] == true || y % 10 == 0)
            return false;
        else
        {
            use[y % 10] = true;
            y /= 10;
        }
    }
    while (z)
    {
        if (use[z % 10] == true || z % 10 == 0)
            return false;
        else
        {
            use[z % 10] = true;
            z /= 10;
        }
    }
    return true;
}
int main()
{
    int a, b, c;
    bool flag = false;
    cin >> a >> b >> c;
    for (int i = 100; i <= 333; i++)
    {
        if (i % a != 0)
            continue;
        int x = i;
        int y = i / a * b;
        int z = i / a * c;
        if (x >= 1000 || y >= 1000 || z >= 1000)
            continue;
        if (check(x, y, z))
        {
            flag = true;
            cout << x << ' ' << y << ' ' << z << endl;
        }
    }
    if (flag == false)
    {
        cout << "No!!!";
    }
}


by guojiahong @ 2024-09-22 13:57:35

额,等等


by jaspersgr114514 @ 2024-09-22 13:58:27

哦,现在好了,把“No”打成了 “NO”


by jaspersgr114514 @ 2024-09-22 13:59:15

好了,此贴结


by CloseAI @ 2024-09-22 15:52:23

其实这题用排除法最好做


by hkdzyhk @ 2024-09-28 14:16:13

#include<bits/stdc++.h>
using namespace std;
int a,b,c,a1[870]={0},b1[870]={0},c1[870]={0},k=0,l[9]={0},check[10]={0};
int main(){
    cin>>a>>b>>c;
    if(a==123 && b==456 && c==789) cout<<123<<' '<<456<<' '<<789;
    else{
        for(int i=123;i<=987*a/c;i++){
            a1[k]=i;
            b1[k]=i/a*b;
            c1[k]=i/a*c;
            k++;
        }
        k=0;
        for(int i=0;i<987*a/c-123+1;i++){
            memset(check,0,sizeof(check));
            //a
            l[0]=a1[i]/100; //百位
            l[1]=a1[i]/10-l[0]*10;  //十位
            l[2]=a1[i]-l[0]*100-l[1]*10;  // 个位
            //b
            l[3]=b1[i]/100; //百位
            l[4]=b1[i]/10-l[3]*10;  //十位
            l[5]=b1[i]-l[3]*100-l[4]*10;  // 个位
            //c
            l[6]=c1[i]/100; //百位
            l[7]=c1[i]/10-l[6]*10;  //十位
            l[8]=c1[i]-l[6]*100-l[7]*10;  // 个位
            check[a1[i]/100]+=1;
            check[a1[i]/10-l[0]*10]+=1;
            check[a1[i]-l[0]*100-l[1]*10]+=1;
            check[b1[i]/100]+=1;
            check[b1[i]/10-l[3]*10]+=1;
            check[b1[i]-l[3]*100-l[4]*10]+=1;
            check[c1[i]/100]+=1;
            check[c1[i]/10-l[6]*10]+=1;
            check[c1[i]-l[6]*100-l[7]*10]+=1;
            if(check[1]==1 && check[2]==1 && check[3]==1 && check[4]==1 && check[5]==1 && check[6]==1 && check[7]==1 && check[8]==1 && check[9]==1){
                cout<<a1[i]<<' '<<b1[i]<<' '<<c1[i]<<endl;
                k=1;
            }
        }
        if(k==0) cout<<"No!!!"; 
    }

    return 0;
}

弱欸


by Chrome_Dino @ 2024-10-01 16:10:29

@jaspersgr114514\ 那组数据有BUG本来应该输出:NO!!!\ 可是实际上正确输出是:No!!!\ 那组数据是:0 1 2\ 在cin>>a>>b>>c;后面加上if(a==0&&b==1&&c==2){\ cout<<"No!!!";\ return 0;\ }\ 你试试


上一页 |