卑微蒟蒻求助,80分,第五个点过不去

P1618 三连击(升级版)

chenchenwwww @ 2020-02-03 18:06:01

#include<set>
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c;
    int i=0;
    int A,B,C;
    int flag = 0;
    scanf("%d%d%d",&A,&B,&C);
    for(i =123;i<330;i++)
    {
        a = A*i;
        b = B*i;
        c = C*i;
        if(b>1000||c>1000){

            break;
        }
        set<int> s;
        s.insert(a%10);
        s.insert(a/100);
        s.insert((a/10)%10);
        s.insert(b%10);
        s.insert(b/100);
        s.insert((b/10)%10);
        s.insert(c%10);
        s.insert(c/100);
        s.insert((c/10)%10);
        if(s.size()==9&&(s.find(0))==(s.end()))
        {/*将九个数塞入集合,集合大小为九并且集合中没有0元素则找到了*/
            printf("%d %d %d\n",i,b,c);
            flag = 1;
        }

    }
    if(!flag) printf("No!!!");
    return 0;
}

by wulibra @ 2020-02-04 23:04:52

直接说答案不太好,给个提示吧:

比例不一定只存在个位比个位

这也是这道题的坑点所在...


by chenchenwwww @ 2020-02-05 10:45:46

@wulibra 感谢,我没想那么多


by SpiritWalk @ 2020-02-10 20:07:06

#include <stdio.h>
int main()
{
    int a,b,c;
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    int x;
    int number[9];
    int ret = 0;

    for(x=123;x<988;x++){
        if(x%A==0){
            a = x;
            b = x/A*B;
            c = x/A*C;

            number[0] = a % 10;
            a /= 10;
            number[1] = a % 10;
            a /= 10;
            number[2] = a % 10;

            number[3] = b % 10;
            b /= 10;
            number[4] = b % 10;
            b /= 10;
            number[5] = b % 10;

            number[6] = c % 10;
            c /= 10;
            number[7] = c % 10;
            c /= 10;
            number[8] = c % 10;

            int m,n;
            int prime = 1;
            for(m=0;m<9;m++){
                for(n=m+1;n<9;n++){
                    if(number[m]==number[n] || number[m]==0){
                        prime = 0;
                        break;
                    }
                }
                if(prime==0){
                    break;
                }
            }
            if(prime==1){
                printf("%d %d %d\n",x,x/A*B,x/A*C);
                ret = 1;
            }
        }
    }

    if(ret == 0){
        printf("No!!!\n");
    }

    return 0;
}

我考虑到了非个位数的情况啊,为什么还是不对呢


|