5 条题解

  • 2
    @ 2024-6-18 9:28:15

    @EraYes 你渴望点赞吗?

    • @ 2024-6-18 9:36:04

      我渴望分享知识 😧

  • 0
    @ 2025-3-31 9:57:14

    kc2班yyy小恐龙高达1000分谁敢挑战

  • -1
    @ 2024-6-17 17:00:29

    C++Python都可以使用内置全排列来实现本题。

    C++algorithm库提供了next_permutation()用来生成排列

    C++

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    int main() {
        vector<int> digits = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        while (next_permutation(digits.begin(), digits.end())){
            int num1 = digits[0] * 100 + digits[1] * 10 + digits[2];
            int num2 = digits[3] * 100 + digits[4] * 10 + digits[5];
            int num3 = digits[6] * 100 + digits[7] * 10 + digits[8];
            if (num2 == 2 * num1 && num3 == 3 * num1)
                printf("%d    %d    %d\n", num1, num2, num3);
        }
        return 0;
    }
    

    Pythonitertools库提供了全排列迭代器permutations

    from typing import List
    from itertools import permutations
    
    digits: List[int] = list(range(1, 10))
    for perm in permutations(digits):
        num1: int = perm[0] * 100 + perm[1] * 10 + perm[2];
        num2: int = perm[3] * 100 + perm[4] * 10 + perm[5];
        num3: int = perm[6] * 100 + perm[7] * 10 + perm[8];
        if num2 == 2 * num1 and num3 == 3 * num1:
            print(f"{num1}    {num2}    {num3}")
    

    当然,这里的全排列会有许多冗余的排列生成,比如num1 > 333 时,往后产生的数都不可能是答案,所以剩下的优化就交给你了。 😸

    • -2
      @ 2025-4-7 11:49:36

      我是天才

      #include

      using namespace std;

      int main() { cout<<"192 384 576"<<endl; cout<<"219 438 657"<<endl; cout<<"273 546 819"<<endl; cout<<"327 654 981"<<endl; return 0; }

      • -3
        @ 2025-5-16 11:50:45
        a=[0]*10
        for i in range(123,334):
            s=0
            for j in range(1,10):
                a[j]=0
            for k in range(1,4):
                n=k*i
                a[n%10]=1
                a[n//10%10]=1
                a[n//100]=1
            for m in range(1,10):
                s+=a[m]
            if s==9:
                print(str(i)+" "+str(2*i)+" "+str(3*i))
        
        

        more easy

        print("192 384 576\n219 438 657\n273 546 819\n327 654 981")
        
        • 1

        【桶思想的应用】验证数据存在性

        信息

        ID
        912
        时间
        1000ms
        内存
        256MiB
        难度
        4
        标签
        (无)
        递交数
        218
        已通过
        105
        上传者