为什么都超时。。。弱鸡求助

P1618 三连击(升级版)

helpcyg @ 2020-06-03 21:23:23

题目:

直接贴代码

#include<iostream>
using namespace std;
bool same(int A[],int B[],int C[]){
    int times = A[0]*A[1]*A[2]*B[0]*B[1]*B[2]*C[0]*C[1]*C[2],plus = A[0]+A[1]+A[2]+B[0]+B[1]+B[2]+C[0]+C[1]+C[2];
    if((times == 362880)&&(plus == 45)){
        return false;
    }
    return true;
}
int main(){
    int one,two,three,count = 0;
    cin>>one>>two>>three;
    for(int i = 123;i < 988;i++){
        for(int j = i + 1;j < 988;j++){
            for(int h = j + 1;h < 988;h++){
                int a[3],b[3],c[3];
                a[0] = i % 10;
                a[1] = i / 10 % 10;
                a[2] = i / 100;

                b[0] = j % 10;
                b[1] = j / 10 % 10;
                b[2] = j / 100;

                c[0] = h % 10;
                c[1] = h / 10 % 10;
                c[2] = h / 100;     
                if(j % i == 0 && h % i == 0){
                    if((j / i == two && h / i == three) && (!same(a,b,c))){
                        cout<<i<<" "<<j<<" "<<h<<endl;
                        count++;
                    }
                }
            }
        }
    }
    if(count == 0){
        cout<<"No!!!";
    }
    return 0;
}

by helpcyg @ 2020-06-03 21:32:38

emmmmmm


by infinities @ 2020-06-03 21:33:01

我被开除OIer学生籍(

难道我是退休后人士前来学OI?(弥天大雾


by helpcyg @ 2020-06-03 21:33:53

算了,我放弃了,反正又不提交,输出对了就行(奸笑)但还是要谢谢各位,第一次让我明白了时间复杂度的重要性


by helpcyg @ 2020-06-03 21:34:09

???


by FZzzz @ 2020-06-03 21:47:33

现在学循环循环之前都不教时间复杂度的吗


by helpcyg @ 2020-06-14 21:10:16

@FZzzz 啊,我老师没教


by 123321V @ 2020-08-29 23:14:36

自己算算你3个for循环循环的次数,三个次数相乘你应该会吧?


by 123321V @ 2020-08-29 23:19:30

你时间复杂度有1亿多了吧


上一页 |