暴力方法第二个点过不了,求教

P1618 三连击(升级版)

godperkz @ 2018-08-14 19:15:19

include<iostream>

include<algorithm>

using namespace std; bool self(int n) { int n1=n/100; int n2=n%10; int n3=((n-n2)/10)%10; if(n1!=n2&&n2!=n3&&n1!=0&&n2!=0&&n3!=0) return 1; else return 0; } bool same(int o,int p) { int o1=o/100; int o2=o%10; int o3=((o-o2)/10)%10; int p1=p/100; int p2=p%10; int p3=((p-p2)/10)%10; if(o1!=p1&&o1!=p2&&o1!=p3&&o2!=p1&&o2!=p2&&o2!=p3&&o3!=p1&&o3!=p2&&o3!=p3) return 1; else return 0; } int main() { int a,b,c,t,t1=0,swi=0,ot1,ot2; cin>>a>>b>>c; int m=a+b+c; int i,j,k; for(i=1;i<=9;i++) {

for(j=1;j<=9;j++)
{

for(k=1;k<=9;k++)
{
    t=i*100+j*10+k;
    if(t>1000*c/m)
    {
        break;
        swi=1;
    }
    if(i!=j&&j!=k)
    {
        if(t%a==0)
        {
            ot1=t*b/a;
            ot2=t*c/a;
            if(self(ot1)&&self(ot2)&&ot2<1000&&self(t))
            {
                if(same(t,ot1)&&same(t,ot2)&&same(ot1,ot2))
                {
                    cout<<t<<" "<<ot1<<" "<<ot2<<endl;
                    t1=1;
                }
            }
        }
    }
}
if(swi==1)
break;
}
if(swi==1)
break;
}
if(t1==0)
cout<<"No!!!"<<endl;
return 0;

}


by skiy_gyx @ 2018-08-14 19:17:08

楼主,你这是一半Markdown一半不是啊


by Uichiha_Itachi @ 2018-08-14 19:20:41

奇怪排版


by godperkz @ 2018-08-15 12:43:34

#include<iostream>
#include<algorithm>
using namespace std;
bool self(int n)
{
int n1=n/100;
int n2=n%10;
int n3=((n-n2)/10)%10;
if(n1!=n2&&n2!=n3&&n1!=0&&n2!=0&&n3!=0)
return 1;
else 
return 0;
}
bool same(int o,int p)
{
int o1=o/100;
int o2=o%10;
int o3=((o-o2)/10)%10;
int p1=p/100;
int p2=p%10;
int p3=((p-p2)/10)%10;
if(o1!=p1&&o1!=p2&&o1!=p3&&o2!=p1&&o2!=p2&&o2!=p3&&o3!=p1&&o3!=p2&&o3!=p3)
return 1;
else
return 0;
}
int main()
{
int a,b,c,t,t1=0,swi=0,ot1,ot2;
cin>>a>>b>>c;
int m=a+b+c; 
int i,j,k;
for(i=1;i<=9;i++)
{

for(j=1;j<=9;j++)
{

for(k=1;k<=9;k++)
{
    t=i*100+j*10+k;
    if(t>1000*c/m)
    {
        break;
        swi=1;
    }
    if(i!=j&&j!=k)
    {
        if(t%a==0)
        {
            ot1=t*b/a;
            ot2=t*c/a;
            if(self(ot1)&&self(ot2)&&ot2<1000&&self(t))
            {
                if(same(t,ot1)&&same(t,ot2)&&same(ot1,ot2))
                {
                    cout<<t<<" "<<ot1<<" "<<ot2<<endl;
                    t1=1;
                }
            }
        }
    }
}
if(swi==1)
break;
}
if(swi==1)
break;
}
if(t1==0)
cout<<"No!!!"<<endl;
return 0;
}   

by godperkz @ 2018-08-15 12:44:04

新入洛谷,对排版还不太熟悉,见谅


|