第六个测试点RE,求助

P1618 三连击(升级版)

Zmeiying @ 2023-08-11 17:29:26

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
    int a,b,c,tmp=0,tmp2=0,l,m,n;
    cin>>a>>b>>c;
    int x,y,z,o,p,w;
    x=0;
    y=0;
    z=0;
    int e[10],d[10];
    memset(d,0,sizeof(d));
    for(int i=1;i<=9;i++)
        e[i]=i;
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
            for(int k=1;k<=9;k++){
                n=0;
                m=0;
                l=0;
                w=0;
                p=0;
                o=0;
                x=i*100+j*10+k;
                y=x*b/a;
                z=y*c/b;
                if(y<1000 && z<1000){
                    n=y%10;
                    m=(y%100-n)/10;
                    l=(y-y%100)/100;
                    w=z%10;
                    p=(z%100-w)/10;
                    o=(z-z%100)/100;

            //  cout<<x<<" "<<y<<" "<<z<<" "<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<m<<" "<<n<<" "<<o<<" "<<p<<" "<<w<<" ";
                memset(d,0,sizeof(d));

                for(int q=1;q<=9;q++){
                    /*if(i==e[q] || k==e[q] || j==e[q] || l==e[q] || m==e[q] || n==e[q] || o==e[q] || p==e[q] || w==e[q])
                    d[q]++;*/
                    if(i==e[q]) d[q]++;
                    if(j==e[q]) d[q]++;
                    if(k==e[q]) d[q]++;
                    if(l==e[q]) d[q]++;
                    if(m==e[q]) d[q]++;
                    if(n==e[q]) d[q]++;
                    if(o==e[q]) d[q]++;
                    if(p==e[q]) d[q]++;
                    if(w==e[q]) d[q]++;
                }
                for(int q=1;q<=9;q++){
                    if(d[q]!=1) tmp=1;
                }
                //cout<<x;
                if(tmp==0){
                    cout<<x<<" "<<y<<" "<<z<<endl;
                    tmp2=1;
                }
                }
                //cout<<endl;
                tmp=0;
            }
    if(tmp2==0) cout<<"No!!!";  
    return 0;
}

by Magic_1e6 @ 2023-08-11 17:47:00

把数组开大点,放全局区里


by JunhanWang @ 2023-08-11 17:54:53

#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int e[10],d[10];
int main(){
    int a,b,c,tmp=0,tmp2=0,l,m,n;
    cin>>a>>b>>c;
    if(a==0)
    {
        cout<<"No!!!";
        return 0;
    }
    int x,y,z,o,p,w;
    x=0;
    y=0;
    z=0;
    memset(d,0,sizeof(d));
    for(int i=1;i<=9;i++)
        e[i]=i;
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
            for(int k=1;k<=9;k++){
                n=0;
                m=0;
                l=0;
                w=0;
                p=0;
                o=0;
                x=i*100+j*10+k;
                y=x*b/a;
                z=y*c/b;
                if(y<1000 && z<1000){
                    n=y%10;
                    m=(y%100-n)/10;
                    l=(y-y%100)/100;
                    w=z%10;
                    p=(z%100-w)/10;
                    o=(z-z%100)/100;

            //  cout<<x<<" "<<y<<" "<<z<<" "<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<m<<" "<<n<<" "<<o<<" "<<p<<" "<<w<<" ";
                memset(d,0,sizeof(d));

                for(int q=1;q<=9;q++){
                    /*if(i==e[q] || k==e[q] || j==e[q] || l==e[q] || m==e[q] || n==e[q] || o==e[q] || p==e[q] || w==e[q])
                    d[q]++;*/
                    if(i==e[q]) d[q]++;
                    if(j==e[q]) d[q]++;
                    if(k==e[q]) d[q]++;
                    if(l==e[q]) d[q]++;
                    if(m==e[q]) d[q]++;
                    if(n==e[q]) d[q]++;
                    if(o==e[q]) d[q]++;
                    if(p==e[q]) d[q]++;
                    if(w==e[q]) d[q]++;
                }
                for(int q=1;q<=9;q++){
                    if(d[q]!=1) tmp=1;
                }
                //cout<<x;
                if(tmp==0){
                    cout<<x<<" "<<y<<" "<<z<<endl;
                    tmp2=1;
                }
                }
                //cout<<endl;
                tmp=0;
            }
    if(tmp2==0) cout<<"No!!!";  
    return 0;
}

注意一下a是0的死翘翘情况


by Zmeiying @ 2023-08-12 15:47:20

谢谢dalao 解决了


by Dreamzsf @ 2023-08-22 11:16:56

@JunhanWang 666


|