想问一下各位大佬我的这个想法是有什么问题吗

P1618 三连击(升级版)

bata22368030 @ 2023-11-06 10:54:10

#include<bits/stdc++.h>
using namespace std;
int num[100], a, b, c,r=0;
int tem;
int flag1, flag2, flag3,flag=0;

int main() {
    cin >> a >> b >> c;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            for (int k = 1; k <= 9; k++) {
                if ((i != j) && (j != k) && (k != i)) {
                    num[r++] = 100 * i + 10 * j + k;

                }
            }
        }
    }

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < r; j++) {
            for (int k = 0; k < r; k++) {
                flag1 = num[i] /a;
                flag2 = num[j] / b;
                flag3 = num[k] /c;
                if ((flag1 == flag2) &&(flag2== flag3)) {
                    cout << flag1 << " " << flag2 << " " << flag3 << endl;
                    flag = 1;
                }
            }
        }
    }
    if (flag == 0) {
        cout << "No!!!";
    }
    return 0;
}

by hopelessness @ 2023-11-06 11:23:48

@bata22368030 首先你没有去重,其次,你用int/int会向下取整


by BGM114514 @ 2023-11-06 11:27:10

在极限数据下,r怎么说也有900,而900^3729000000,怎么说都得T飞。


by hopelessness @ 2023-11-06 11:29:56

@BGM114514 Ta这不仅仅是TLE的问题啊


by BGM114514 @ 2023-11-06 11:31:12

@hopelessness 那是当然


by hopelessness @ 2023-11-06 11:34:42

@bata22368030 你可以枚举 9! 种情况


|