题解

83 条题解

  • 0
    @ 2018-03-01 11:09:12

    import java.util.HashSet;
    import java.util.Set;

    public class Main {
    public static void main(String[] args){
    for(int i=123;i<330;i++){
    int a = i;
    int b = i * 2;
    int c = i * 3;
    if(confirm(String.valueOf(a), String.valueOf(b), String.valueOf(c))){
    System.out.println(a+" "+b+" "+c);
    }
    }
    }

    private static boolean confirm(String a, String b, String c){
    Set<String> set = new HashSet<String>();
    for(int i=0;i<3;i ++){
    set.add(a.substring(0, 1));
    set.add(b.substring(0, 1));
    set.add(c.substring(0, 1));
    a = a.substring(1);
    b = b.substring(1);
    c = c.substring(1);
    }
    if(set.size() == 9 && !set.contains("0")){
    return true;
    }else{
    return false;
    }
    }
    }

  • 0
    @ 2018-02-26 21:46:09
    #include<bits/stdc++.h>
    int main(){
        char s[10];
        bool flag[10]={0},flag2=0;
        for(int i=123;i<=329;++i){
            sprintf(s+1,"%d%d%d",i,i*2,i*3);
            flag[0]=1;//确保0不出现
            for(int j=1;j<=9;++j) if(1^flag[s[j]-'0']) flag[s[j]-'0']=1;else flag2=1;//用异或保证每个数字只出现一次
            if(!(flag2)) printf("%d %d %d\n",i,i*2,i*3);
            memset(flag,0,sizeof(flag));flag2=0;
        }
    }
    
  • 0
    @ 2018-02-09 22:36:34

    java来一波,感觉想复杂了。

    public class FillNumber {
    
        public static void main(String[] args) {
            for (int i = 100; i <= 334; i ++) {
                int num1 = i;
                int num2 = i * 2;
                int num3 = i * 3;
                if(isConform(num1,num2,num3)) {
                    System.out.println(num1 + " " + num2 + " " + num3);
                }
            }
            
    
        }
        public static boolean isConform(int a, int b, int c) {
            int[] arr = new int[9];
            boolean[] check = new boolean[9];
            for (int i = 0; i < 9; i ++) {
                arr[i] = i + 1;
                check[i] = true;
            }
            int a1 = a % 10; int a2 = (a / 10) % 10; int a3 = a / 100;
            int b1 = b % 10; int b2 = (b / 10) % 10; int b3 = b / 100;
            int c1 = c % 10; int c2 = (c / 10) % 10; int c3 = c / 100;
            for (int i = 0; i < arr.length; i ++) {
                if (check[i]) {
                    if (arr[i] == a1 || arr[i] == a2 || arr[i] == a3) {
                        check[i] = false;
                        continue;
                    }
                    if (arr[i] == b1 || arr[i] == b2 || arr[i] == b3) {
                        check[i] = false;
                        continue;
                    }
                    if (arr[i] == c1 || arr[i] == c2 || arr[i] == c3) {
                        check[i] = false;
                        continue;
                    }
                }
            }
            boolean flag = true;
            for (int i = 0; i < check.length; i ++) {
                if (check[i]) {
                    flag = false;
                }
            }
            if(flag) {
                return true;
            }
            return false;
        }   
    }
    
  • 0
    @ 2017-12-02 14:43:42

    //直接输出答案233~~
    #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;
    }

  • 0
    @ 2017-11-29 13:00:39

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

  • 0
    @ 2017-10-03 11:38:54

    //不解释
    #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;
    }

  • 0
    @ 2017-10-03 09:09:20

    稳到没毛病!(不是我做的)

    #include<iostream>
    #include<algorithm>
    #include<string>
    using namespace std;
    int t[10];
    int b1,b2,b3,c,m=0;
    int main()
    {
    for(int i=1;i<=9;i++)
    for(int j=1;j<=9;j++)
    for(int k=1;k<=9;k++)
    {
    if(i==j||i==k||j==k)continue;
    for(int q=1;q<=9;q++)
    t[q]=0;
    t[i]++;
    t[j]++;
    t[k]++;
    b1=i*100+j*10+k;
    b2=b1*2;
    if(b2>999)break;
    t[b2/100]++;
    t[(b2%100)/10]++;
    t[b2%10]++;
    b3=b1*3;
    if(b3>999)break;
    t[b3/100]++;
    t[(b3%100)/10]++;
    t[b3%10]++;
    c=0;
    for(int x=1;x<=9;x++)
    {
    if(t[x]==1) c++;
    }
    if(c==9)cout<<b1<<" "<<b2<<" "<<b3<<endl;
    }
    return 0;
    }

  • 0
    @ 2017-10-03 09:08:08

    #include<iostream>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int main()
    {
    //freopen("digital.in","r",stdin);
    //freopen("digital.out","w",stdout)
    cout<<"192 384 576"<<endl;
    cout<<"219 438 657"<<endl;
    cout<<"273 546 819"<<endl;
    cout<<"327 654 981"<<endl;
    return 0;
    }

  • 0
    @ 2017-09-26 23:01:29

    .......
    ```cpp
    #include<cstdio>
    #include<cstring>
    char s[10];
    bool b[10];
    bool pd(int x)
    {
    sprintf(s,"%d%d%d",x,x*2,x*3);
    memset(b,0,sizeof(b));
    for(int i=0;s[i];i++)
    {
    if(s[i]=='0')return false;
    if(b[s[i]-'0'])return false;
    b[s[i]-'0']=true;
    }
    return true;
    }
    int main()
    {
    for(int i=123;i*3<=999;i++)
    if(pd(i))
    printf("%d %d %d\n",i,i*2,i*3);
    return 0;
    }

  • 0
    @ 2017-08-08 14:11:37
    
    
    var i,a,b,c:longint;
        ch,ch1,ch2:string;
    
    function max(x,y,z:longint):longint;
    var i,j,t:longint;
      a:array[1..3]of longint;
    begin
      t:=0;
      a[1]:=x; a[2]:=y; a[3]:=z;
      for i:=1 to 3-1 do
      for j:=i+1 to 3 do if a[i]<a[j] then begin  t:=a[j]; a[j]:=a[i]; a[i]:=t; end;
      exit(a[1]);
    end;
    function f(s:string):boolean;
    var c:char;
    begin
        for c:='1'to'9'do
            if pos(c,s)=0 then exit(false);
        exit(true);
    end;
    begin
      readln(a,b,c); a:=1; b:=2; c:=3;
        for i:=123 to 1000 div max(a,b,c)   do
        begin
            str(i*a,ch);
            str(i*b,ch1);
            str(i*c,ch2);
            ch:=ch+ch1+ch2;
            if f(ch)then writeln(i*a,' ',i*b,' ',i*c);
        end;
    end.
    
  • 0
    @ 2017-08-02 17:05:15

    打表万岁!!!
    先暴力找出来,然后写打表
    ```cpp
    #include<iostream>
    using namespace std;

    int main()
    {
    std::ios::sync_with_stdio(false);
    cout<<"192 384 576"<<endl;
    cout<<"219 438 657"<<endl;
    cout<<"273 546 819"<<endl;
    cout<<"327 654 981"<<endl;
    }
    ```

  • 0
    @ 2017-08-02 13:54:00
    
    Var
         i,j,k,l,sum,num,num1,sum1:longint;
         a,f:array[0..9]of integer;
         ch:boolean;
    Begin
         for i:=1 to 9 do
              for j:=1 to 9 do
                   for k:=1 to 9 do
                   if (i<>j) and (j<>k) and (i<>k) then
                   begin
                        fillchar(a,sizeof(a),0);
                        a[1]:=i; a[2]:=j; a[3]:=k;
                        num:=i*100+j*10+k;
                        if (num*2>999) or (num*3>999) then
                             continue;
                        num1:=num*2; sum:=num1;
                        a[4]:=num1 mod 10; num1:=num1 div 10;
                        a[5]:=num1 mod 10; num1:=num1 div 10;
                        a[6]:=num1 mod 10; num1:=num1 div 10;
                        num1:=num*3; sum1:=num1;
                        a[7]:=num1 mod 10; num1:=num1 div 10;
                        a[8]:=num1 mod 10; num1:=num1 div 10;
                        a[9]:=num1 mod 10; num1:=num1 div 10;
                        ch:=true;
                        fillchar(f,sizeof(f),0);
                        for l:=1 to 9 do
                             inc(f[a[l]]);
                        for l:=1 to 9 do
                             if f[l]<>1 then
                                  ch:=false;
                        if ch then
                             writeln(num,' ',sum,' ',sum1);
                   end;
         readln;
    End.
    
    
    

    如果今年的题目像这样简单就好,,水题水过。。。

  • 0
    @ 2017-07-22 17:47:46

    #include<cstdio>
    int main(){printf("192 384 576\n219 438 657\n273 546 819\n327 654 981");}
    打表
    93Bytes

  • 0
    @ 2017-07-05 19:55:21

    #include <stdio.h>
    #include<iostream>
    using namespace std;
    void Getnum(int x, int a[], int n){ //计算个十百位上的数并存到数组中去
    while (x != 0){
    a[n - 1] = x % 10;
    x = x / 10;
    n--;
    }
    }
    bool Have_same(int a[]){//判断一个数组中有没有相同的数
    if (a[0] != a[1] && a[0] != a[2] && a[1] != a[2]){
    return true;
    }
    else return false;
    }
    bool Is_true(int a[], int b[]) { //比较3个数各位置上的数是否相同并查找是否包括0,0不在这几个数中
    for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
    if (a[i] == b[j]||a[i]==0||b[j]==0){ return false; }
    }
    }
    return true;
    }
    int main() //123456789一共9个数,满足条件构造3个数
    {
    int num1, num2, num3; //存放3个不同的数
    int num11[3], num22[3], num33[3]; //3个数组存放每个数个十百位上的数
    for (int i = 123; i <= 329; i++){ //从最小的数123循环到最大的数329就可以找到所有的数
    if ((i % 10) != 0){
    num1 = i;
    num2 = 2 * i;
    num3 = 3 * i;
    Getnum(num1, num11, 3);
    Getnum(num2, num22, 3);
    Getnum(num3, num33, 3);
    if (Is_true(num11, num22) && Is_true(num11, num33) && Is_true(num33, num22) && Have_same(num11) && Have_same(num22) && Have_same(num33)) {
    cout << num1 << ' ' << num2 << ' ' << num3 << endl;
    }
    }
    }
    system("pause");
    }

  • 0
    @ 2017-07-05 19:55:06

    #include <stdio.h>
    #include<iostream>
    using namespace std;
    void Getnum(int x, int a[], int n){ //计算个十百位上的数并存到数组中去
    while (x != 0){
    a[n - 1] = x % 10;
    x = x / 10;
    n--;
    }
    }
    bool Have_same(int a[]){//判断一个数组中有没有相同的数
    if (a[0] != a[1] && a[0] != a[2] && a[1] != a[2]){
    return true;
    }
    else return false;
    }
    bool Is_true(int a[], int b[]) { //比较3个数各位置上的数是否相同并查找是否包括0,0不在这几个数中
    for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
    if (a[i] == b[j]||a[i]==0||b[j]==0){ return false; }
    }
    }
    return true;
    }
    int main() //123456789一共9个数,满足条件构造3个数
    {
    int num1, num2, num3; //存放3个不同的数
    int num11[3], num22[3], num33[3]; //3个数组存放每个数个十百位上的数
    for (int i = 123; i <= 329; i++){ //从最小的数123循环到最大的数329就可以找到所有的数
    if ((i % 10) != 0){
    num1 = i;
    num2 = 2 * i;
    num3 = 3 * i;
    Getnum(num1, num11, 3);
    Getnum(num2, num22, 3);
    Getnum(num3, num33, 3);
    if (Is_true(num11, num22) && Is_true(num11, num33) && Is_true(num33, num22) && Have_same(num11) && Have_same(num22) && Have_same(num33)) {
    cout << num1 << ' ' << num2 << ' ' << num3 << endl;
    }
    }
    }
    system("pause");
    }

  • 0
    @ 2017-06-22 20:53:45

    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    bool isvalid(const int &val,bool vis[]){
    int num=val;
    int a,b,c;
    a=num/100;
    num-=(a*100);
    b=num/10;
    c=num%10;
    if(a==b||a==c||b==c)return false;
    if(a==0||b==0||c==0)return false;
    vis[a]=1;
    vis[b]=1;
    vis[c]=1;
    return true;
    }

    int main(){
    int flag=0;
    for(int i=100;i<=333;++i){
    bool vis[10]={0};
    if(isvalid(i,vis)&&isvalid(2*i,vis)&&isvalid(3*i,vis)){
    for(int j=1;j<10;++j){
    if(!vis[j]){
    flag=1;
    break;
    }
    }
    if(!flag)cout<<i<<" "<<2*i<<" "<<3*i<<"\n";
    flag=0;
    }
    }
    //system("pause");
    return 0;
    }

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

  • 0
    @ 2017-06-11 21:10:36

    纯数学问题
    不难看出三个数相加一定是6的倍数,可以枚举所有三个数的和可能的情况

    #include<iostream>
    #include<cstring>
    using namespace std;
    int x[4];bool p[10];
    int main()
    {
        int a=606,b=2700,l,i,k;
        for(i=a;i<=b;i+=6)
        {
            memset(p,false,sizeof(p));
            x[1]=i/6;
            x[2]=i/3;
            x[3]=i/2;
            for(k=1;k<=3;k++)
             {
              p[x[k]/100]=true;
              p[(x[k]/10)%10]=true;
              p[x[k]%10]=true;
             }
             for(l=1;l<=9;l++)
              if(!p[l])
               break;
            if(l==10)
            {
                cout<<x[1]<<" "<<x[2]<<" "<<x[3]<<endl;
            }
        }
        return 0;
    }
    
  • 0
    @ 2017-06-04 10:29:14
    #include<iostream>
    #include<string>
    #include<set>
    using namespace std;
    
    void addto_set(set<int>& s, int num)
    {
        int t = 0;
        while (num > 0)
        {
            t = num % 10;
            s.insert(t);
            num = num / 10;
        }
    }
    int main()
    {
    
        //freopen("data.in", "r", stdin);
        //freopen("data.out", "w", stdout);
        
        
        int fir = 0;
        int sec = 0;
        int thir = 0;
        set<int> s;
        set<int>::iterator iter;
        for (fir = 100; fir <= 999; fir++)
        for (sec = 100; sec <= 999;sec++)
        for (thir = 100; thir <= 999; thir++)
        {
            if (2 * fir == sec && 3 * fir == thir)
            {
                s.clear();
                addto_set(s, fir);
                addto_set(s, sec);
                addto_set(s, thir);
                if (s.size() == 9 && (iter=s.find(0))==s.end())
                    cout << fir << " " << sec << " " << thir << " " << endl;
                else
                    continue;
                
            }           
            else
                continue;   
        }
        
        
        return 0;
    }
    
  • 0
    @ 2017-06-03 20:03:09

    终极写法。。我觉得我没法精简下去了

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int comp(const void *a, const void *b){return *(char*)a-*(char*)b;} 
    int main(){
        int i=100,j;
        char a[12];
    w:while(j=1,i++<333){
            sprintf(a,"%d%d%d",i,i*2,i*3);
            qsort(a, 9, sizeof(*a), comp); 
            if(a[0]=='0')continue;
            while(j<9)
                if(a[j]==a[j++-1])goto w;
            printf("%d %d %d\n",i,i*2,i*3);
        }
    }
    
  • 0
    @ 2017-05-18 21:44:27
    //简单粗暴,直接有效
    
    #include<iostream>
    using namespace std;
    bool pan(int a,int b,int c){
        bool num[9]={true,true,true,true,true,true,true,true,true};
        int E[9];
        E[0]=a%10;
        E[1]=a/10%10;
        E[2]=a/100%10;
        E[3]=b%10;
        E[4]=b/10%10;
        E[5]=b/100%10;
        E[6]=c%10;
        E[7]=c/10%10;
        E[8]=c/100%10;
        for(int i=0;i<=8;i++){
            if(E[i]==0)return false;
            if(num[E[i]-1])num[E[i]-1]=false;
            else {
                return false;
            } 
        }
        return true;
    }
    int main(){
        int a,b,c;
        for(int i=123;i<=987;i++){
            a=i*1;
            b=i*2;
            c=i*3;
            if(b<1000&&c<1000&&pan(a,b,c))cout<<a<<" "<<b<<" "<<c<<endl;
        }
    } 
    

信息

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