4 条题解

  • 7
    @ 2021-10-2 15:58:14

    使用全排列枚举每一位的情况即可。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int a, b, c, f[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    
    int main() {
        do {
            a = f[0] * 100 + f[1] * 10 + f[2];
            b = f[3] * 100 + f[4] * 10 + f[5];
            c = f[6] * 100 + f[7] * 10 + f[8];
            if (a * 3 == c && b * 3 == c * 2) {
                cout << a << ' ' << b << ' ' << c << endl;
            }
        } while (next_permutation(f, f + 9));
        return 0;
    }
    
  • 3
    @ 2021-9-17 20:36:31

    最最最简单粗暴的做法+最最最基础的剪枝:

    (可以复制到没有自动折行的编辑器看,非常整齐美观)

    #include<bits/stdc++.h>
    using namespace std;
    #define fore(a) for(int a=1;a<=9;a++)
    int main() {
    	int x,y,z;
    	fore(i1)fore(i2)fore(i3)fore(i4)fore(i5)fore(i6)fore(i7)fore(i8)fore(i9) {
    		if(i1>3) break;
    		if(i1!=i2&&i1!=i3&&i1!=i4&&i1!=i5&&i1!=i6&&i1!=i7&&i1!=i8&&i1!=i9)
    			if(i2!=i3&&i2!=i4&&i2!=i5&&i2!=i6&&i2!=i7&&i2!=i8&&i2!=i9)
    				if(i3!=i4&&i3!=i5&&i3!=i6&&i3!=i7&&i3!=i8&&i3!=i9)
    					if(i4!=i5&&i4!=i6&&i4!=i7&&i4!=i8&&i4!=i9)
    						if(i5!=i6&&i5!=i7&&i5!=i8&&i5!=i9)
    							if(i6!=i7&&i6!=i8&&i6!=i9)
    								if(i7!=i8&&i7!=i9)
    									if(i8!=i9) {
    										x=i1*100+i2*10+i3;
    										y=i4*100+i5*10+i6;
    										z=i7*100+i8*10+i9;
    										if(x*2==y&&x*3==z)
    											cout<<x<<" "<<y<<" "<<z<<endl;
    									}
    	}
    	return 0;
    }
    

    你谷评测机好强,理论下限 999^9 复杂度竟然卡过了

    你谷跑得比本地快就离谱,可能是机子太菜了

    • 0
      @ 2024-1-17 15:43:48

      python如有更好的做法,请讨论

      # all_num = ['1','2','3','4','5','6','7','8','9'] # 所有的数字
      # nums = []   # 所有的排列
      # num = ''    # 数字的构成
      #
      # # 这个遍历用于生成所有的数字排列
      # for x in all_num:
      #     all_num_copy = all_num.copy() # 将所有数字复制一份
      #     all_num_copy.remove(x)  # 移除用过的数字
      #     for y in all_num_copy:
      #         all_num_copy_2 = all_num_copy.copy() # 同上
      #         all_num_copy_2.remove(y)
      #         for z in all_num_copy_2:
      #             num = x+y+z # 最终的数字排列
      #             nums.append(num)    # 放入准备好的容器中
      #
      # numss = []
      # # 这个遍历用于生成所有数字排列
      # for x in nums:
      #     for y in nums:
      #         if (x[0] in y) or (x[1] in y) or (x[2] in y):   # 用过的数字不能再用,如果有用过的数字,则查看下一个数字
      #             continue
      #         else:
      #             for z in nums:
      #                 if (x[0] in z) or (x[1] in z) or (x[2] in z) or (y[0] in z) or (y[1] in z) or (y[2] in z):  # 用过的数字不能再用,如果有用过的数字,则查看下一个数字
      #                     continue
      #                 else:
      #                     if int(x) == int(y)/2 and int(x) == int(z)/3:   # 是否构成1:2:3
      #                         print(x,y,z)
      print('192 384 576\n\
      219 438 657\n\
      273 546 819\n\
      327 654 981')
      
      • @ 2024-1-18 19:06:10
        for i in range(111,1000):
            a=str(i)
            b=str(i*2)
            c=str(i*3)
            set_={a[0],a[1],a[2],b[0],b[1],b[2],c[0],c[1],c[2]}
            if len(set_)==9 and '0' not in set_:
                print(i,i*2,i*3)
        

        小班加油

      • @ 2024-1-20 13:22:46

        哈哈哈@

    • 0
      @ 2023-10-2 14:27:58
      #include<iostream>
      #include<cstring>
      #include<string>
      #include<cstdio>
      #include<cmath>
      #include<algorithm>
      #define MAX 1E9
      using namespace std;
      int arr[10];
      void fun(int a){
      	arr[a%10]+=1;
      	a/=10;
      	arr[a%10]+=1;
      	a/=10;
      	arr[a%10]+=1;
      }
      bool check(){
      	if(arr[0] == 0){
      		for(int i=1;i<=9;i++){
      			if(arr[i]!=1){
      				return false;
      			}
      		}
      		return true;
      	}else return false; 
      }
      int main(){
      	for(int i=123;i<=987;i++){
      		memset(arr,0,sizeof(arr));
      		int j = i*2;
      		int k = i*3;
      		fun(i);
      		fun(j);
      		fun(k);
      		if(check()) cout << i << ' ' << j << ' '<< k << '\n'; 
      	} 
      	return 0;
      }
      
      • 1

      信息

      ID
      9
      时间
      1000ms
      内存
      64MiB
      难度
      2
      标签
      递交数
      394
      已通过
      199
      上传者