大佬快进来!!!

P1618 三连击(升级版)

Nina__happy @ 2024-09-29 18:31:14

求助求助!! 蒟蒻在此,谁敢你看你看,这么可怜的一只蒟蒻孤零零地站在这里,你忍心吗


using namespace std;
int main()
{
    int a,b,c,flag=0;
    cin>>a>>b>>c;
    for(int num=100;num<=333;num++){
        for(int sum=300;sum<=666;sum++){
            for(int cnt=576;cnt<=999;cnt++){
                int i=num%1000/100;
                int j=num%100/10;
                int l=num%10;
                int a=sum%1000/100;
                int b=sum%100/10;
                int c=sum%10;
                int x=cnt%1000/100;
                int y=cnt%100/10;
                int z=cnt%10;
                if(i!=j&&i!=l&&i!=a&&i!=b&&i!=c&&i!=x&&i!=y&&i!=z&&j!=l&&j!=a&&j!=b&&j!=c&&j!=x&&j!=y&&j!=z&&l!=a&&l!=b&&l!=c&&l!=x&&l!=y&&l!=z&&a!=b&&a!=c&&a!=x&&a!=y&&a!=z&&b!=c&&b!=x&&b!=y&&b!=z&&c!=x&&c!=y&&c!=z&&x!=y&&x!=z&&y!=z&&i!=0&&j!=0&&l!=0&&a!=0&&b!=0&&c!=0&&x!=0&&y!=0&&z!=0){
                    if(num/a*b==sum&&num/a*c==cnt){
                        cout<<num<<" "<<sum<<" "<<cnt<<endl;
                        flag++;
                    }
                }
            }
        }
    } 
    if(flag==0){
        cout<<"No!!!";
    }
    return 0;
}

by Zmk2009 @ 2024-09-29 18:46:02

巨佬的做法有点奇怪,建议巨佬换个思路。将 9个数字全排列,分别取1-3,4-6,7-9位,组成三个三位数,然后再判断,是否满足A:B:C 复杂度O(9!)足够通过


by ElisaQR @ 2024-09-29 18:49:25


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int aa,bb,cc,flag=0;
    cin>>aa>>bb>>cc;
    if(!aa){
        cout<< "No!!!";
        return 0;
    }
    for(int num=100;num<=999;num++){
        for(int sum=num+1;sum<=999;sum++){
            for(int cnt=sum+1;cnt<=999;cnt++){
                int i=num/100;
                int j=num/10%10;
                int l=num%10;
                int a=sum/100;
                int b=sum/10%10;
                int c=sum%10;
                int x=cnt/100;
                int y=cnt/10%10;
                int z=cnt%10;
                if(i!=j&&i!=l&&i!=a&&i!=b&&i!=c&&i!=x&&i!=y&&i!=z&&j!=l&&j!=a&&j!=b&&j!=c&&j!=x&&j!=y&&j!=z&&l!=a&&l!=b&&l!=c&&l!=x&&l!=y&&l!=z&&a!=b&&a!=c&&a!=x&&a!=y&&a!=z&&b!=c&&b!=x&&b!=y&&b!=z&&c!=x&&c!=y&&c!=z&&x!=y&&x!=z&&y!=z&&i!=0&&j!=0&&l!=0&&a!=0&&b!=0&&c!=0&&x!=0&&y!=0&&z!=0){
                    if(num/aa*bb==sum&&num/aa*cc==cnt&&num%aa==0){
                        cout<<num<<" "<<sum<<" "<<cnt<<endl;
                        flag++;
                    }
                }
            }
        }
    } 
    if(flag==0){
        cout<<"No!!!";
    }
    return 0;
}

by ElisaQR @ 2024-09-29 18:49:34

@Nina__happy


by Nina__happy @ 2024-09-29 18:51:04

@Zmk2009 感谢感谢


by ElisaQR @ 2024-09-29 18:51:13

@Nina__happy 范围错了,忽略0的情况,然后变量重名,也没考虑num/a无法整除的情况


by Zmk2009 @ 2024-09-29 18:57:34

@Nina__happy 不客气,不过别忘了A,B,C 可能是小数


by Nina__happy @ 2024-09-29 18:58:53

@zly 感谢感谢


|