哎,果然全TLE,哪位大佬知道咋改

P1618 三连击(升级版)

AC_710GD @ 2024-01-11 21:55:14

#include<bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, sum1, sum2, sum3, gcd1, gcd2, gcd, ans1, ans2, ans3, d1, d2, d3, e1, e2, e3, f1, f2, f3;
    bool flag = 0;
    scanf("%d%d%d", &a, &b, &c);
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            for (int k = 1; k <= 9; k++) {
                for (int d = 1; d <= 9; d++) {
                    for (int e = 1; e <= 9; e++) {
                        for (int f = 1; f <= 9; f++) {
                            for (int g = 1; g <= 9; g++) {
                                for (int h = 1; h <= 9; h++) {
                                    for (int l = 1; l <= 9; l++) {
                                        sum1 = i * 100 + j * 10 + k;
                                        sum2 = d * 100 + e * 10 + f;
                                        sum3 = g * 100 + h * 10 + l;
                                        gcd1 = __gcd(sum1, sum2);
                                        gcd2 = __gcd(sum2, sum3);
                                        gcd = __gcd(gcd1, gcd2);
                                        ans1 = sum1 / gcd;
                                        ans2 = sum2 / gcd;
                                        ans3 = sum3 / gcd;
                                        d1 = sum1 % 10;
                                        d2 = sum1 / 10 % 10;
                                        d3 = sum1 / 100;
                                        e1 = sum2 % 10;
                                        e2 = sum2 / 10 % 10;
                                        e3 = sum2 / 100;
                                        f1 = sum3 % 10;
                                        f2 = sum3 / 10 % 10;
                                        f3 = sum3 / 100;
                                        if (ans1 == a && ans2 == b && ans3 == c && sum1 < sum2 && sum2 < sum3 && d1!=d2 && d1!=d3 && d1!=e1 && d1!=e2 && d1!=e3 && d1!=f1 && d1!=f2 && d1!=f3 && d2!=d3 && d2!=e1 && d2!=e2 && d2!=e3 && d2!=f1 && d2!=f2 && d2!=f3 && d3!=e1 && d3!=e2 && d3!=e3 && d3!=f1 && d3!=f2 && d3!=f3 && e1!=e2 && e1!=e3 && e1!=f1 && e1!=f2 && e1!=f3 && e2!=e3 && e2!=f1 && e2!=f2 && e2!=f3 && e3!=f1 && e3!=f2 && e3!=f3 && f1!=f2 && f1!=f3 && f2!=f3) {
                                            printf("%d %d %d\n", sum1, sum2, sum3);
                                            //printf("%d %d %d\n", ans1, ans2, ans3);
                                            flag = 1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!flag) {
        printf("No!!!");
    }
    return 0;
}

by AC_710GD @ 2024-01-11 22:10:43

对<(^-^)>


by AC_710GD @ 2024-01-11 22:11:55

<(^-^)> @ACaCaca_

┗|`O′|┛ 嗷~~

?


by a1co0av5ce5az1cz0ap_ @ 2024-01-11 22:22:39


by AC_710GD @ 2024-01-11 22:26:24

@ACaCaca_

没啥

OK了


by Zjy_AK_IOI @ 2024-01-12 17:57:14

@AC_710GD 人有continue!


by AC_710GD @ 2024-01-13 01:22:56

@Zjy_AK_IOI

???


by Zjy_AK_IOI @ 2024-01-13 17:05:48

@AC_710GD 题解有continue,次数会减少


by AC_710GD @ 2024-01-14 15:44:21

@Zjy_AK_IOI

ok


by hanxiao0 @ 2024-01-29 17:41:58

这段代码除了输入1,2,3,其他结果都是错的


by sqz11111 @ 2024-02-11 11:53:14

@AC_710GD 可以用next_permutation呀 用一个数组a[9]={1,2,3,4,5,6,7,8,9}


上一页 | 下一页