隨筆 - 71  文章 - 15  trackbacks - 0
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          因為口渴,上帝創造了水;
          因為黑暗,上帝創造了火;
          因為我需要朋友,所以上帝讓你來到我身邊
          Click for Shaanxi xi'an, Shaanxi Forecast
          ╱◥█◣
            |田|田|
          ╬╬╬╬╬╬╬╬╬╬╬
          If only I have such a house!
          〖總在爬山 所以艱辛〗
          Email:myesjoy@yahoo.com.cn
          NickName:yesjoy
          MSN:myesjoy@hotmail.com
          QQ:150230516

          〖總在尋夢 所以苦痛〗

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          Hibernate在線

          Java友情

          Java認證

          linux經典

          OA系統

          Spring在線

          Structs在線

          專家專欄

          企業信息化

          大型設備共享系統

          工作流

          工作流產品

          網上購書

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           1 //求出用1,2,5這三個數不同個數組合的和為1000的組合個數。
           2 //如:100個1是一個組合,5個1加19個5是一個組合。。。。
           3   public class getNumbers{ 
           4    public static void sums1(int temp)
           5    {
           6    int num1 = temp/1;
           7    int num2 = temp/2;
           8    int num3 = temp/5;
           9    int numbers = 0;
          10    String values; 
          11    for(int i=0;i<num1;i++)
          12    {
          13    for(int j=0;j<num2;j++)
          14    {
          15    for(int k=0;k<num3;k++)
          16    {
          17    if((1*i+2*j+5*k)==temp)
          18    {
          19    numbers++
          20    values = i+“個1,“+j+“個2,“+k+“個5“;
          21    System.out.println(“the “+numbers+“ groups numbers is:“+values);
          22    }
          23    }
          24    }
          25    }
          26    System.out.println(“the numbers of group is ===>+numbers);
          27    }
          28    public static void main(String[] args) {
          29    int s = 1000;
          30    sums1(s);
          31    }
          32   }
          33   
           1 運行結果:
           2   E:\java\ProgramJava\csdn>javac getNumbers.java
           3   E:\java\ProgramJava\csdn>java getNumbers >>groups.txt
           4   groups.txt中的輸出結果如下:
           5   the 1 groups numbers is:0個1,5個2,198個5
           6   the 2 groups numbers is:0個1,10個2,196個5
           7   the 3 groups numbers is:0個1,15個2,194個5
           8   the 4 groups numbers is:0個1,20個2,192個5
           9   the 5 groups numbers is:0個1,25個2,190個5
          10   the 6 groups numbers is:0個1,30個2,188個5
          11   the 7 groups numbers is:0個1,35個2,186個5
          12   the 8 groups numbers is:0個1,40個2,184個5
          13   the 9 groups numbers is:0個1,45個2,182個5
          14   the 10 groups numbers is:0個1,50個2,180個5
          15   the 11 groups numbers is:0個1,55個2,178個5
          16   the 12 groups numbers is:0個1,60個2,176個5
          17   the 13 groups numbers is:0個1,65個2,174個5
          18   the 14 groups numbers is:0個1,70個2,172個5
          19   the 15 groups numbers is:0個1,75個2,170個5
          20   the 16 groups numbers is:0個1,80個2,168個5
          21   …………
          22   the 50379 groups numbers is:983個1,6個2,1個5
          23   the 50380 groups numbers is:984個1,3個2,2個5
          24   the 50381 groups numbers is:984個1,8個2,0個5
          25   the 50382 groups numbers is:985個1,0個2,3個5
          26   the 50383 groups numbers is:985個1,5個2,1個5
          27   the 50384 groups numbers is:986個1,2個2,2個5
          28   the 50385 groups numbers is:986個1,7個2,0個5
          29   the 50386 groups numbers is:987個1,4個2,1個5
          30   the 50387 groups numbers is:988個1,1個2,2個5
          31   the 50388 groups numbers is:988個1,6個2,0個5
          32   the 50389 groups numbers is:989個1,3個2,1個5
          33   the 50390 groups numbers is:990個1,0個2,2個5
          34   the 50391 groups numbers is:990個1,5個2,0個5
          35   the 50392 groups numbers is:991個1,2個2,1個5
          36   the 50393 groups numbers is:992個1,4個2,0個5
          37   the 50394 groups numbers is:993個1,1個2,1個5
          38   the 50395 groups numbers is:994個1,3個2,0個5
          39   the 50396 groups numbers is:995個1,0個2,1個5
          40   the 50397 groups numbers is:996個1,2個2,0個5
          41   the 50398 groups numbers is:998個1,1個2,0個5
          42   the numbers of group is ===>50398
          43   
           1   #include<iostream>
           2   using namespace std;
           3   void main()
           4   {
           5    int i,j,n=0;
           6    for(i=0;i<=20;i++)
           7    {
           8    for(j=0;j<=(100-i*5)/2;j++)
           9    {
          10    n++;
          11    }
          12    }
          13    cout<<n<<endl;
          14   }
           1   #include <stdio.h>
           2   int main(void)
           3   {
           4    int j,k,n;
           5   
           6    for(j=0;j<=50;j++)
           7    {
           8    for(k=0;k<=20;k++)
           9    {
          10    if(2*j+5*k<=100)
          11    n++;
          12    }
          13    }
          14    
          15    printf(“count=%d\n“,n);
          16   }
          posted on 2006-01-19 14:51 ★yesjoy★ 閱讀(2034) 評論(2)  編輯  收藏 所屬分類: 算法總結

          FeedBack:
          # re: 求出用1,2,5這三個數不同個數組合的和為1000的組合個數(華為面試題目) 2006-10-02 22:04 執著人生
          #include<iostream.h>
          void main()
          {
          int sum = 0;
          int i,j,k;
          for(i = 0; i <= 1000; ++i)
          for(j = 0;j <= 500;++j)
          for(k = 0; k <= 200;++k)
          {
          if(1*i + 2*j + 5*k == 1000)
          ++sum;
          }
          cout<<"The result is : "<<sum;
          }  回復  更多評論
            
          # re: 求出用1,2,5這三個數不同個數組合的和為1000的組合個數(華為面試題目) 2006-10-02 22:07 執著人生
          樓主的少考慮了全1情況  回復  更多評論
            
          主站蜘蛛池模板: 太康县| 盐山县| 呈贡县| 澄城县| 潼关县| 龙口市| 合山市| 巩留县| 山东| 扎囊县| 延川县| 五指山市| 陕西省| 房山区| 吴川市| 河池市| 阳信县| 卢湾区| 曲靖市| 惠安县| 宜君县| 昌邑市| 钟山县| 沁水县| 兴山县| 中西区| 卢龙县| 泉州市| 肇庆市| 新龙县| 论坛| 本溪市| 昌图县| 松溪县| 安丘市| 乌拉特前旗| 成武县| 金坛市| 麦盖提县| 化隆| 儋州市|