求助一下

P1618 三连击(升级版)

lizhuorong @ 2023-11-18 16:54:24

60分的代码:

#include <cmath>
#include<bits/stdc++.h>
using namespace std;
int z[8];
bool f(int a,int b,int c)
{
    z[0]=a/100;
    z[1]=a/10%10;
    z[2]=a%10;
    z[3]=b/100;
    z[4]=b/10%10;
    z[5]=b%10;
    z[6]=c/100;
    z[7]=c/10%10;
    z[8]=c%10;
    if(z[0]+z[1]+z[2]+z[3]+z[4]+z[5]+z[6]+z[7]+z[8]!=45||z[0]*z[1]*z[2]*z[3]*z[4]*z[5]*z[6]*z[7]*z[8]!=362880){
        return false;
    }
    return true;
}
int main(){
    int a,b,c,k;
    cin>>a>>b>>c;
    int z;
    int num=0;
    int a1,a2,a3,a4,a5,a6,a7,a8,a9;
    k=__gcd(__gcd(a,b),c); 
    a/=k;b/=k;c/=k;  
    for(int i=1;i<=999;i++){
        int A=a*i,B=b*i,C=c*i;
        if(f(A,B,C)){
            num=1;
            cout<<A<<" "<<B<<" "<<C<<endl;

        }

    }

    if(num=0){
        cout<<"No!!!";
    }
}

by shiyueheng @ 2023-11-18 17:03:38

@lizhuorong

#include<bits/stdc++.h>

using namespace std;

int main()

{
    int a,b,c,n[10],s=1,flag=1;

    cin>>a>>b>>c;

    for(int i=1;i<=333;i++)

    {
        int m[10]={0};

        flag=1;

        int d=a*i;

        int e=b*i;

        int f=c*i;

        n[0]=d/100;

        n[1]=d%100/10;

        n[2]=d%10;

        n[3]=e/100;

        n[4]=e%100/10;

        n[5]=e%10;

        n[6]=f/100;

        n[7]=f%100/10;

        n[8]=f%10;

        for(int j=0;j<9;j++)

        {

            for(int k=1;k<=9;k++)

            {

                if(n[j]==k)

                {

                    m[k]++;

                }

            }

     }

        for(int j=1;j<=9;j++)

        {

            if(m[j]!=1)

            {

                flag=0;

            }

        }

        if(flag==1)

        {

            cout<<d<<' '<<e<<' '<<f<<endl;

            s=0;
        }

    }

    if(s==1)

    {
        cout<<"No!!!";
    }

    return 0;

}

by lizhuorong @ 2023-11-18 17:04:43

@shiyueheng 谢谢


by shiyueheng @ 2023-11-18 17:05:12

100分代码


|