24h購物| | PChome| 登入
2009-03-14 20:17:19| 人氣624| 回應0 | 上一篇 | 下一篇

ACM 725 Q725: Division

推薦 0 收藏 0 轉貼0 訂閱站台

希望有更好的解,這樣好暴力

/************************************************************/

#include<stdio.h>
#include<stdlib.h>
int ans[80][63][10],nn[80]={0};
main()
{   
 int a,b,c,d,e,a1,b1,c1,d1,e1,flag=0,m;
    for(a=0;a<10;a++)
     {
      for(b=0;b<10;b++)
        {
         if(a==b) continue;
         for(c=0;c<10;c++)
          {
           if(c==a||c==b) continue;
            for(d=0;d<10;d++)
              {
               if(d==a||d==b||d==c) continue;
               for(e=0;e<10;e++)
                {
                if(e==a||e==b||e==c||e==d) continue;
                 for(a1=0;a1<10;a1++)
                  {
                   if(a1==a||a1==b||a1==c||a1==d||a1==e) continue;
                   for(b1=0;b1<10;b1++)
                     {
                      if(b1==a||b1==b||b1==c||b1==d||b1==e||b1==a1) continue;
                      for(c1=0;c1<10;c1++)
                        {
                         if(c1==a||c1==b||c1==c||c1==d||c1==e||c1==a1||c1==b1) continue; 
                          for(d1=0;d1<10;d1++)
                           {
                            if(d1==a||d1==b||d1==c||d1==d||d1==e||d1==a1||d1==b1||d1==c1) continue;
                             for(e1=0;e1<10;e1++)
                               {
                                if(e1==a||e1==b||e1==c||e1==d||e1==e||e1==a1||e1==b1||e1==c1||e1==d1) continue;
                                if((a*10000+b*1000+c*100+d*10+e)%(a1*10000+b1*1000+c1*100+d1*10+e1)==0)
                                 {
                                  m=(a*10000+b*1000+c*100+d*10+e)/(a1*10000+b1*1000+c1*100+d1*10+e1);
                                  ans[m][nn[m]][0]=a;
                                  ans[m][nn[m]][1]=b;
                                  ans[m][nn[m]][2]=c;
                                  ans[m][nn[m]][3]=d;
                                  ans[m][nn[m]][4]=e;
                                  ans[m][nn[m]][5]=a1;
                                  ans[m][nn[m]][6]=b1;
                                  ans[m][nn[m]][7]=c1;
                                  ans[m][nn[m]][8]=d1;
                                  ans[m][nn[m]][9]=e1;
                                  nn[m]=nn[m]+1;
                                 }
                               }
                           }
                           /*d1*/
                        }
                        /*c1*/
                     }
                     /*b1*/
                  }  
                  /*a1*/
                } 
              }
          }
        }  
     } 
 int n,aa;
 while(scanf("%d",&n)==1&&n!=0)
   {
   
     if(nn[n]==0) printf("There are no solutions for %d.\n",n);
     else
      {
        for(aa=0;aa<nn[n];aa++)
         printf("%d%d%d%d%d / %d%d%d%d%d = %d\n",ans[n][aa][0],ans[n][aa][1],ans[n][aa][2],ans[n][aa][3],ans[n][aa][4],ans[n][aa][5],ans[n][aa][6],ans[n][aa][7],ans[n][aa][8],ans[n][aa][9],n);
      }
      printf("\n");
   }
 return 0;
}

 

台長: 來源不明
人氣(624) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: ACM |
此分類下一篇:ACM 514 Rails
此分類上一篇:ACM 256 Q256: Quirksome Squares

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文