DFS解

P1618 三连击(升级版)

SkywalkerLiACMer @ 2020-02-01 17:49:41

深度优先搜索标准题

#include<stdio.h>
#include<math.h>
int sum=0,A,B,C;
int book[10],a[10];
void dfs(int step,int x,int y,int z)
{  
    int i;
    if(step==10)
    {
      A=a[1]*100+a[2]*10+a[3];
       B=a[4]*100+a[5]*10+a[6];
        C=a[7]*100+a[8]*10+a[9];
         if(A*y==B*x&&B*z==C*y)     
            {
              printf("%d %d %d\n",A,B,C);
              sum++;
            }
        return;
    }

    for(i=1;i<=9;i++)
    {
        if(book[i]==0)
        {
         a[step]=i;
         book[i]=1;
         dfs(step+1,x,y,z);
         book[i]=0;
        }
    }
    return; 
}
int main()
{
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
      dfs(1,x,y,z);
    if(sum==0) printf("No!!!");

    return 0;
}

by He_Ren @ 2020-02-01 17:59:07

中国竞赛的希望


by Kubic @ 2020-02-01 18:01:00

我们的红太阳!


by SkywalkerLiACMer @ 2020-02-01 20:20:21

@He_Ren (手动滑稽)


by He_Ren @ 2020-02-01 20:40:07

@SkywalkerLiACMer 讨论区题解违法规定,快删帖


by GoldenFishX @ 2020-02-17 18:16:34

SQLM


|