隨筆-48  評(píng)論-26  文章-0  trackbacks-0
             問題:
                      有17個(gè)人圍成一圈(編號(hào)0~16),從第0號(hào)的人開始從1報(bào)數(shù),凡報(bào)到3的倍數(shù)的人離開圈子,
                      然后再數(shù)下去,直到最后只剩下一個(gè)人為止,問此人原來的位置是多少號(hào)?

            
          int [] people = new int[17];
              
          int lastPeople = 0;
              
          public void getTheLastPeople(){       
                  
          for(int i = 0; i < people.length; i++){
                      people[i] 
          = i+1;
                  }
                  
          int count = 0;
                  
          int countLast = 0;
                  
          int j = 0;
                  
          while(true){
                      
          for(j = 0; j < people.length; j++){               
                          
          if(people[j] != 0){
                              count
          ++;
                              people[j] 
          = count;
                              System.out.println(
          "people[" + j + "] = " + people[j]);
                              
          if (people[j] % 3 == 0) {
                                  people[j] 
          = 0;
                                  countLast
          ++;
                                  
          if(countLast == 17){
                                      lastPeople 
          = j;
                                      
          return;
                                  }
                              }
                          }
                      }           
                  }
              }
          posted on 2009-09-26 14:35 Worker 閱讀(151) 評(píng)論(0)  編輯  收藏 所屬分類: 算法/數(shù)據(jù)結(jié)構(gòu)

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          主站蜘蛛池模板: 姜堰市| 威海市| 孟村| 宿迁市| 自贡市| 黎城县| 新津县| 陇川县| 平阳县| 大足县| 伊宁县| 克拉玛依市| 河源市| 海南省| 同仁县| 班戈县| 甘洛县| 清镇市| 娄底市| 汕头市| 新蔡县| 齐齐哈尔市| 蓬莱市| 化德县| 保山市| 莲花县| 泽库县| 新安县| 安平县| 光泽县| 寻甸| 枞阳县| 措勤县| 油尖旺区| 宜黄县| 罗定市| 威信县| 吴桥县| 安达市| 辽中县| 武强县|