萌新求助大佬

P1618 三连击(升级版)

LXLS @ 2019-03-01 22:54:26

只得40分,除​1,4点都WA了 求大佬能帮忙看下代码,万分感谢大佬们

#include<iostream>
using namespace std;
int a[5],b[5],c[5];
int q,w,e,ppt = 1;
int main()
{
    cin >> q >> w >> e;
    for(int i = 123;i <= 999; i++)
    {
        a[1] = i / 100;
        a[2] = i / 10 % 10;
        a[3] = i % 100 % 10;
        b[1] = i / q * w / 100;
        b[2] = i / q * w / 10 % 10;
        b[3] = i / q * w % 100 % 10;
        c[1] = i / q * e / 100;
        c[2] = i / q * e / 10 % 10;
        c[3] = i / q * e % 100 % 10;
        if(a[1] + a[2] + a[3] + b[1] + b[2] + b[3] + c[1] + c[2] + c[3] == 45 && a[1] * a[2] * a[3] * b[1] * b[2] * b[3] * c[1] * c[2] * c[3] == 362880)
        {
            ppt = 0;
            cout << i << " " << i / q * w << " " << i / q * e << endl;
        }
    }
    if(ppt)
    {
        cout <<"NO!!!" <<endl;
    }
    return 0;
}


by 童年如作业 @ 2019-03-01 22:56:17

@LXLS 选择代码语言啊

#include<iostream>
using namespace std;
int a[5],b[5],c[5];
int q,w,e,ppt = 1;
int main()
{
    cin >> q >> w >> e;
    for(int i = 123;i <= 999; i++)
    {
        a[1] = i / 100;
        a[2] = i / 10 % 10;
        a[3] = i % 100 % 10;
        b[1] = i / q * w / 100;
        b[2] = i / q * w / 10 % 10;
        b[3] = i / q * w % 100 % 10;
        c[1] = i / q * e / 100;
        c[2] = i / q * e / 10 % 10;
        c[3] = i / q * e % 100 % 10;
        if(a[1] + a[2] + a[3] + b[1] + b[2] + b[3] + c[1] + c[2] + c[3] == 45 && a[1] * a[2] * a[3] * b[1] * b[2] * b[3] * c[1] * c[2] * c[3] == 362880)
        {
            ppt = 0;
            cout << i << " " << i / q * w << " " << i / q * e << endl;
        }
    }
    if(ppt)
    {
        cout <<"NO!!!" <<endl;
    }
    return 0;
}

by 童年如作业 @ 2019-03-01 22:57:35

@LXLS 敢问你学过了吗


by LXLS @ 2019-03-01 22:58:25

#include<iostream>
using namespace std;
int a[5],b[5],c[5];
int q,w,e,ppt = 1;
int main()
{
    cin >> q >> w >> e;
    for(int i = 1;i <= 987; i++)
    {
        a[1] = i / 100;
        a[2] = i / 10 % 10;
        a[3] = i % 100 % 10;
        b[1] = i / q * w / 100;
        b[2] = i / q * w / 10 % 10;
        b[3] = i / q * w % 100 % 10;
        c[1] = i / q * e / 100;
        c[2] = i / q * e / 10 % 10;
        c[3] = i / q * e % 100 % 10;
        if(a[1] + a[2] + a[3] + b[1] + b[2] + b[3] + c[1] + c[2] + c[3] == 45 && a[1] * a[2] * a[3] * b[1] * b[2] * b[3] * c[1] * c[2] * c[3] == 362880)
        {
            ppt = 0;
            cout << i << " " << i / q * w << " " << i / q * e << endl;
        }
    }
    if(ppt)
    {
        cout <<"NO!!!" <<endl;
    }
    return 0;
}

by LXLS @ 2019-03-01 22:59:05

@童年如作业 什么什么QAQ...


by LXLS @ 2019-03-01 23:05:07

no写成NO了..... 但也还是得了80,最后一个点WA了 求大佬帮助QAQ


by 童年如作业 @ 2019-03-01 23:06:04

实际上你思路有问题……

你只用把 A:B:CABC三个数不断翻倍就行了。例如样例,从一倍(1,2,3)开始,不断地把倍数+1,二倍(2,4,6),三倍(4,5,6)……(选择性忽略无意义枚举)……一百倍(100,200,300),一百九十二倍(192,384,576),二百一十九倍(219,438,657),以此类推,再在这些数中寻找符合题目条件的即可


by LXLS @ 2019-03-01 23:08:58

@童年如作业 感谢大佬,我去琢磨琢磨 QAQ


by 童年如作业 @ 2019-03-01 23:09:47

@LXLS 这是我的核心代码(由于我码的输入输出对你不友好我删了)

for(register int i=1;c*i<=999;i++)
    {
        if(a*i<100) continue;
        bool t=true;
        int ta=a*i,tb=b*i,tc=c*i;
        memset(pd,0,sizeof(pd));
        while(ta>0)
        {
            if(pd[ta%10]==1||ta%10==0)
            {
                t=false;
                break;
            }
            pd[ta%10]=1;
            ta/=10;
        }
        while(tb>0&&t)
        {
            if(pd[tb%10]==1||tb%10==0)
            {
                t=false;
                break;
            }
            pd[tb%10]=1;
            tb/=10;
        }
        while(tc>0&&t)
        {
            if(pd[tc%10]==1||tc%10==0)
            {
                t=false;
                break;
            }
            pd[tc%10]=1;
            tc/=10;
        }
}

by LXLS @ 2019-03-01 23:11:50

@童年如作业 好的好的,感谢帮助


by yizimi远欣 @ 2019-03-02 00:46:55

QwQ


| 下一页