5 条题解

  • 2
    @ 2025-2-10 20:07:56

    2.8洛谷讨论区倒闭来的 本人的第1篇题解

    思路

    这题只需要枚举a,b,c a,b,c 的值就行了,然后把数字拆分后用桶的思想挨个检查即可。 至于a的枚举范围从最小(123)到 1000/3 就行。 一定记得清0

    Code

    #include<bits/stdc++.h>
    using namespace std;
    int hydro[11]; // 用桶的思想来检查是否每个数只用一次
    int main(){
        for(int a=123;a<=1000/3;a++){ 
        	memset(hydro,0,sizeof(hydro));//一定记得清0!
            int b = 2*a;
            int c = 3*a;
            /*
            三位数的拆分:
            个位:x(/1)%10
            十位:x/10%10
            百位:x/100(%10)
            */
            hydro[a/100]++;
            hydro[a/10%10]++;
            hydro[a%10]++;
            hydro[b/100]++;
            hydro[b/10%10]++;
            hydro[b%10]++;
            hydro[c/100]++;
            hydro[c/10%10]++;
            hydro[c%10]++;
            bool flag = true;
            for(int i=1;i<=9;i++){
                if(hydro[i] != 1){
                    flag = false;
                }
            }
            if(flag == true){
                cout << a << " " << b << " " << c << endl;
            }
        }
        return 0;
    }
    /* 
    附上自己算的:
    192 384 576
    219 438 657
    273 546 819
    327 654 981
    */
    
    • 0
      @ 2025-3-10 16:53:22

      思路:

      • 数字位于123到987之间;且不能重复;所以需要使用某种方式标记数字1-9是否被使用;
        • 用int充当位图来存储1-9是否完全覆盖;
      #include <iostream>
      using namespace std;
      int status = 0;
      /**
      * 将value每个位上的数字所对应的位置设置为1,表示存在;
      * eg. 3 ==> 0b1000;右移三位
      * param value: 数字
      */
      void set_bit(int value){
          while(value>0){
              status |= 1 << (value%10);
              value /=10;
          }
      }
      
      int main(){
          for(int i = 123; i < 333; ++i){
              set_bit(i);
              set_bit(i*2);
              set_bit(i*3);
              int ob = status & 0b1111111110;
              if(ob==0b1111111110){
                  cout<<i<<" "<<i*2<<" "<<i*3<<endl;
              }
              status = 0;
          }
          return 0;
      }
      
      • 0
        @ 2025-2-25 23:09:50

        用for循环每次硬推出来

        AC code(求点赞)

        //抄题解不有趣
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            for(int i=123;i<333;i++){
                int a[10]={0},b[10]={0},c[10]={0};
                a[1]=i%100%10;
                a[2]=i%100/10;
                a[3]=i/100;
                b[1]=2*i%10%10;
                b[2]=2*i%100/10;
                b[3]=2*i/100;
                c[1]=3*i%10%10;
                c[2]=3*i%100/10;
                c[3]=3*i/100;
                if(a[1]*a[2]*a[3]*b[1]*b[2]*b[3]*c[1]*c[2]*c[3]==362880&&a[1]+a[2]+a[3]+b[1]+b[2]+b[3]+c[1]+c[2]+c[3]==45){
                    cout<<i<<" "<<i*2<<" "<<i*3<<endl;
                }
            }
            return 0;
        }
        
        • 0

          硬算的 #include<bits/stdc++.h> 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; }

        • 0
          @ 2024-11-4 17:39:27
          
          #include<bits/stdc++.h>
          using namespace std;
          int a,b,c; 
          int main(){
          	  for(a=123;a<=333; a++) {
          		b=2*a;
          		c=3*a;
          		if(((a/100)+(a/10%10)+(a%10)+(b/100)+(b/10%10)+(b%10)+(c/100)+(c/10%10)+(c%10)==1+2+3+4+5+6+7+8+9)&&(a/100)*(a /10%10)*(a%10)*(b/100)*(b/10%10)*(b%10)*(c/100)*(c/10%10)*(c % 10)==1*2*3*4*5*6*7*8*9){
          			cout<<a<<' '<<b<<' '<<c<<endl;
          		}
          	}
          	return 0;
          }
          
          • @ 2025-1-24 21:01:37

            牛逼,我还在用破dfs

        • 1

        信息

        ID
        5066
        时间
        1000ms
        内存
        64MiB
        难度
        2
        标签
        递交数
        643
        已通过
        341
        上传者