题解

83 条题解

  • 15
    @ 2018-09-03 18:48:31

    #include<iostream>
    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;
    }

  • 7
    @ 2018-09-02 18:30:27

    致小白

    #include <iostream>
    using namespace std;
    int main()
    { 
       int x,a,a1,a2,a3,b,b1,b2,b3,c,c1,c2,c3;
       for(x=123;x<=333;x++) 
       {
       a=x;b=x*2;c=x*3;
       a1=a%10;
       a2=a/10%10;
       a3=a/100;
       b1=b%10;
       b2=b/10%10;
       b3=b/100;
       c1=c%10;
       c2=c/10%10;
       c3=c/100;
       if(a1*a2*a3*b1*b2*b3*c1*c2*c3==362880)
        cout<<a<<' '<<b<<' '<<c<<endl;
      }
    return 0;
    }
    
  • 5
    @ 2017-03-12 08:56:53

    题解:
    如果顺着题目枚举的话很容易爆;
    所以要反过来想数据之间的关系;
    三个数一定是1:2:3的;
    那么我们只要循环一个基数作为3者公因数就OK,只需循环100~334;
    时间效率prrety高。
    主程序:
    pan判断函数就不贴了

    for i:= 100 to 334 do
    begin
    a1:=1*i; a2:=2*i; a3:=3*i;
    if pan then writeln(a1,' ',a2,' ',a3);
    end;

  • 3
    @ 2018-06-28 18:40:03

    这里提供一个码量较大的代码(可能是我没有圧行)

    思路:

    判断三个数字中是不是只含1~9

    只要排下序再一个个比对就可以啦QAQ

    AC code:

    #include<iostream>
    using namespace std;
    int main(){
        int i,j,k,h,s;
        int a[10];
        for(i=123;i*3<=987;i++){
            for(h=1;h<10;h++)a[h]=0;
            a[i/100]=1;
            a[i/10%10]=1;
            a[i%10]=1;
            j=i*2;
            a[j/100]=1;
            a[j/10%10]=1;
            a[j%10]=1;
            k=i*3;
            a[k/100]=1;
            a[k/10%10]=1;
            a[k%10]=1;
            for(s=0,h=1;h<10;h++)s=s+a[h];
            if(s==9)cout<<i<<" "<<j<<" "<<k<<endl;
        }
        return 0;
    }
    
    
    
  • 3
    @ 2017-07-22 11:27:28

    python 4行代码
    python
    for n in range(123, 330):
    s = str(n) + ' ' + str(2*n) + ' ' + str(3*n)
    if '1' in s and '2' in s and '3' in s and '4' in s and '5' in s and '6' in s and '7' in s and '8' in s and '9' in s:
    print s

  • 1
    @ 2023-07-12 19:51:55

    这道题其实是一个~~水题~~

    看到题目,第一秒想到的就是暴力枚举所有可能的情况

    在边暴力的时候边输出即可

    由于比例为1:2:3
    且都是3位数

    所以:999/3=333

    就得出上限是329,~~因为数字不同~~

    循环代码:

    for(int i=123;i<=329;i++)
    {
        ...
    }
    

    综合AC代码(~~勿抄~~**)**

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        for(int i=123;i<=329;i++)
        {
            int i2=i*2,i3=i*3;
            int a=i%10,b=i/10%10,c=i/100,d=i2%10,e=i2/10%10;
            int f=i2/100,g=i3%10,h=i3/10%10,i1=i3/100;
            if(a*b*c*d*e*f*g*h*i1==362880)
            {
                printf("%d %d %d\n",i,i2,i3); 
            }
        } 
        return 0;
    }
    
  • 1
    @ 2018-05-25 17:42:44

    看了好多方法都比较麻烦,尤其是判断语句过于复杂,这里介绍一种比较简单的java实现

    import java.util.HashSet;
    import java.util.Set;
    
    public class Main {
    
        public static void main(String[] args) {
            Set set = new HashSet<>();
            //遍历第一个数(只需要遍历123-334即可)
            for (int i = 123; i <= 334; i++) {
                    int i2=2*i;
                    int i3=3*i;
                    String string = ""+i+i2+i3;//将3个数转换为一个字符串
                    char[] c=string.toCharArray();//将字符串转为字符数组
                    for (int j = 0; j < c.length; j++) {
                        //将不等于0的字符存放入set集合中
                        if (c[j]!='0') {
                            set.add(c[j]);
                        }else {
                            break;
                        }
                    }
                    //利用set集合不重复的原理,如果set集合长度等于9说明9个数字皆不重复,打印结果
                    if (set.size()==9) {
                        System.out.println(i+" "+i2+" "+i3);
                    }
                    //清除set集合
                    set.clear();
            }
        }
    
    }
    
    
  • 1
    @ 2018-01-02 15:35:29

    #include <stdio.h>
    int main() {
    int min,i,j,flag;
    char all[10];
    for(min = 102; min <=329; min++) {
    sprintf(all,"%d%d%d",min,min*2,min*3);
    flag = 0;
    for(j = 1; j <= 9; j++) {
    for(i = 0; i <=8; i++) {
    if(all[i] == j+'0') {
    flag++;
    break;
    }
    }
    }
    //如果1到9都在字符串出现
    if(flag == 9) {
    printf("%d %d %d\n",min,2*min,3*min);
    }
    }
    return 0;
    }

  • 1
    @ 2017-08-22 19:42:49
    var f:array[1..9]of boolean;i:integer;
    procedure p(a:integer);
    begin
         f[a mod 10]:=false;
         f[a div 10 mod 10]:=false;
         f[a div 100]:=false;
    end;
    function pd(b:integer):boolean;
    var g,s,ba:integer;
    begin
        g:=b mod 10;s:=b div 10 mod 10;ba:=b div 100;
        if (g=s)or(g=ba)or(ba=s)or(f[g]=false)or(f[s]=false)or(f[ba]=false)then exit(true)
        else begin
             p(b);
             exit(false);
        end;
    end;
    begin
       for i:=102 to 329 do begin
           fillchar(f,sizeof(f),true);
           if pd(i) then continue;
           if pd(i*2) then continue;
           if pd(i*3) then continue;
           writeln(i,' ',i*2,' ',i*3);
       end;
    end.
    
    
  • 0
    @ 2023-08-24 12:34:22

    def judge(list):
    dic=['1','2','3','4','5','6','7','8','9']
    flag=0
    for char in dic:
    try:
    list.index(char)
    except:
    flag=1
    return flag

    num=[]
    for i in range(100,334,1):
    num.extend(list(str(i)))
    num.extend(list(str(i*2)))
    num.extend(list(str(i*3)))
    if (not judge(num)):
    print(i,i*2,i*3)
    num=[]

  • 0
    @ 2022-08-16 10:46:56

    next_permutation

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
        int a[10]={1,2,3,4,5,6,7,8,9};
        do {
            int x=a[0]*100+a[1]*10+a[2];
            int y=a[3]*100+a[4]*10+a[5];
            int z=a[6]*100+a[7]*10+a[8];
            if(y%x==0&&y/x==2&&z%x==0&&z/x==3) {
                printf("%d %d %d\n",x,y,z);
            }
        }
        while(next_permutation(a,a+9));
        return 0;
    }
    
  • 0
    @ 2022-01-01 10:39:55

    //借助set容器

    //1772 vijos 巧妙填数
    void test113()
    {
        set<int>s1;
        
        for (int i = 100; i <= 333; i++)
        {
            int p = i;
            int t = 2 * i;
            int m = 3 * i;
            while (p != 0)
            {
                int z = p % 10;
                if(z!=0)
                s1.insert(z);
                p /= 10;
    
            }
            while (t != 0)
            {
                int z = t % 10;
                if(z!=0)
                s1.insert(z);
                t /= 10;
    
            }
            while (m != 0)
            {
                int z = m % 10;
                if(z!=0)
                s1.insert(z);
                m/= 10;
    
            }
            if (s1.size() == 9)
            {
                cout << i << " " << 2 * i <<" "<< 3 * i << endl;
                s1.clear();
            }
            else
            {
                s1.clear();
            }
        }
    
    
    }
    int main()
    {
        test113();
    
    
    }
    
    
  • 0
    @ 2021-11-02 16:19:09
    #include <iostream>
    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;
        //system("pause");
        return 0;
    }
    //xD
    
  • 0
    @ 2021-07-13 10:57:36


    cpp
    #include<stdio.h>
    int main()
    {
    printf("192 384 576\n219 438 657\n273 546 819\n327 654 981");
    return 0;
    }

  • 0
    @ 2021-06-12 21:00:59

    其实由于有第一个的限制,所以我们只用枚举第一个,又因为在第一个不可能在123之前,也不可能在329之后,所以i的大致范围确定,下面是代码

    #include <bits/stdc++.h>
    using namespace std;
    bool b[10];
    bool check(int x){
        while(x>0&&b[x%10]){
            b[x%10]=false;
            x/=10;
        }
        if(x==0)return true;
        else return false;
    }
    int main()
    {
        for(int i=123;i<=329;i++){
            for(int i=1;i<=9;i++){
                b[i]=true;
            }
            if(check(i)&check(i*2)&check(i*3)){
                cout<<i<<" "<<i*2<<" "<<i*3<<endl;
            }
        } 
        return 0;
    }
    
  • 0
    @ 2021-05-31 10:57:38
    
    import java.util.HashSet;
    import java.util.Set;
    
    /**
     * @author wpx
     * @version V1.0
     * @Package com.algorithm
     * @date 2021/5/31 10:44
     */
    public class Main {
        public static void main(String[] args) {
            for(int i = 123; i <= 329; i++) {
    
                String values = i  + " " + (i * 2) + " " + (i * 3);
                if(hasEqualNum(values)){
                    System.out.println(values);
                }
    
            }
        }
    
        public static boolean hasEqualNum(String str){
            Set<Integer> tmpSet = new HashSet<>();
            for(int i = 0; i < str.length(); i++){
                int num = str.charAt(i);
                 if(num == 48){
                    return false;
                }
                if(num == 32){
                    continue;
                }
                if(tmpSet.contains(num)){
                    return false;
                } else {
                    tmpSet.add(num);
                }
            }
            return true;
        }
    
    }
    
    
  • 0
    @ 2020-11-09 15:01:17

    跟大家一样也是从111-333挨个检查,保证三个三位数是由1-9这九个数字组成的方法:把这三个数的每一位存进一个字符串数组中,检查该数组有没有重复的字符,没有就符合要求。
    千万注意,有一种情况是字符中出现了‘0’,一定要排除0的情况

    #include <stdio.h>
    #include <string.h>

    int differ(char ch[]){
    int flag=1;
    int i,j;
    char c;
    for(i=0;i<8;i++){
    c=ch[i];
    for(j=i+1;j<9;j++){
    if(c==ch[j]||c=='0'){
    flag=0;
    break;
    }
    }
    }
    return flag;
    }

    int main()
    {
    int i,double2,triple;
    //注意:double是一个关键词,不能做变量
    int number;
    char num[10];
    for(i=111;i<334;i++){
    double2=2*i;
    triple=3*i;
    number=i;
    num[0]=number/100+'0';
    num[1]=number/10%10+'0';
    num[2]=number%10+'0';

    number=double2;
    num[3]=number/100+'0';
    num[4]=number/10%10+'0';
    num[5]=number%10+'0';

    number=triple;
    num[6]=number/100+'0';
    num[7]=number/10%10+'0';
    num[8]=number%10+'0';

    num[9]='\0';
    if(differ(num)){
    printf("%d %d %d\n",i,double2,triple);
    }
    }
    return 0;
    }

  • 0
    @ 2020-04-20 19:57:01

    next_permutation()是个好东西

    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int r[]={1,2,3,4,5,6,7,8,9};
        while(next_permutation(r,r+9))
        {
            int a=r[0]*100+r[1]*10+r[2];
            int b=r[3]*100+r[4]*10+r[5];
            int c=r[6]*100+r[7]*10+r[8];
            if(a*2==b&&a*3==c)  cout<<a<<" "<<b<<" "<<c<<endl;
        }
        return 0;
    }
    
    
  • 0
    @ 2020-04-19 16:03:46

    头文件并不需要那么多,我只是多写几个常用的省的每次还得再找
    #include<iostream>
    #include<iomanip>
    #include<vector>
    #include<cstdlib>
    #include<array>
    #include<string>
    #include<cmath>
    #include<algorithm>
    #include<cassert>
    using namespace std;
    int x, x1, x2, x3, a[10] = { 0 };
    int main()
    {
    for (x = 123; x < 333; x++)
    {
    x1 = x;
    x2 = x * 2;
    x3 = x * 3;

    a[1] = x1 % 10;
    a[2] = x1 / 10 % 10;
    a[3] = x1 / 100;

    a[4] = x2 % 10;
    a[5] = x2 / 10 % 10;
    a[6] = x2 / 100;

    a[7] = x3 % 10;
    a[8] = x3 / 10 % 10;
    a[9] = x3 / 100;

    sort(a, a + 9);
    int cnt = unique(a, a + 9) - a;
    if (cnt == 9)
    cout << x1 << " " << x2 << " " << x3 << endl;
    }
    return 0;
    }

  • 0
    @ 2020-02-04 19:15:50

    排列组合的思想
    1.1-9全排列
    2.判断是否满足条件
    递归实现全排列
    1.顺序抽取一个数
    2.每当抽取了一个数据之后,对剩下的数据全排列
    3.最后全部抽取完,剩下空字符串

    #include<iostream>
    #include<string>
    #include<cmath>
    using namespace std;
    int a, b, c;
    int num[9];
    bool Judge(int num[]) {//条件判断
        a = 0; b = 0; c = 0;
        int i = 0;
        for (; i < 3; i++)a += num[i] * (int)pow(10, 2 - i);
        for (; i < 6; i++)b += num[i] * (int)pow(10, 5 - i);
        for (; i < 9; i++)c += num[i] * (int)pow(10, 8 - i);
        if (b == 2 * a && c == 3 * a)return true;
        else return false;
    }
    void Count(string x, int n) {//全排列函数
        if (n == 0 && Judge(num))cout << a << " " << b << " " << c << endl;
        else for (int i = 0; i < n; i++) {
            num[9 - n] = x[i] - 48;
            string y = x;
            y.replace(i, 1, "");
            Count(y, n - 1);
        }
    }
    int main()
    {
        Count("123456789", 9);
        return 0;
    }
    

信息

ID
1772
难度
2
分类
搜索 点击显示
标签
递交数
2628
已通过
1269
通过率
48%
被复制
24
上传者