本帖最后由 sqz10200 于 2010-11-16 14:36:01 编辑

解决方案 »

  1.   

    String[] stra = new String[] { "N", "O", "P", "Q", "R", "S", "T", "U","V", "W", "X", "Y", "Z" };
           
    while(stra.length>2){
     for(int i=0;i<stra.length;i++){
           List a=new ArrayList();
        if(( i+1)%3==0){
           stra.remove[i];
        }if(( i+1)%3!=0){ 
                k=0;
          a[k]=stra[i];
         k++;
        } 
    if(i+1-stra.length/3*3>0){
          for(int j=0;j<a.ength;j++){
          stra[j]=a[k];
        }
      }
      return stra;}
      

  2.   


    ArrayList list = new ArrayList();
    for (int i = 1; i <= 13; i++) {
    list.add(i);
    }
    int a = 1;
    int b = 0;
    while (list.size() != 1) {
    if (a % 3 == 0) {
    list.remove(b);
    b--;
    } else {
    b++;
    if (b == list.size()) {
    b = 0;
    }
    }
    a++;
    }
    System.out.println("第" + list.get(0)+"个人剩下了");
      

  3.   


    you有啊我的帖子第一个就是
      

  4.   

    这个一看有点儿类似于队列吧    public void checkStay() {
            String[] stra = new String[] { "N", "O", "P", "Q", "R", "S", "T", "U","V", "W", "X", "Y", "Z" };
            BlockingQueue<String> que = new ArrayBlockingQueue<String>(stra.length,true, Arrays.asList(stra));
            int currentCalled = 0;
            try {
                while (que.size() > 1) {
                    currentCalled++;
                    if (currentCalled == 3) {
                        que.poll();
                        currentCalled = 0;
                    } else {
                        que.put(que.poll());
                    }
                }
                System.out.print(que.poll());
            
           } catch (InterruptedException ex) {
                Logger.getLogger(FinddataServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
      

  5.   


    @Test
    public void dd(){
    String[] arrs = {"N", "O", "P", "Q", "R", "S", "T", "U","V", "W", "X", "Y", "Z"};
    //总人数
    int len = arrs.length;
    //出局人数
    int count = 0;
    //报数器
    int idx = 1;
    //死循环 i%len为数组下标
    for(int i=0;;i++){
    //已经出局,路过
    if("OUT".equals(arrs[i%len])) continue;
    //剩余最后一人
    if(count==len-1){
    System.out.println("游戏结束,最后胜利者为: "+arrs[i%len]);
    break;
    }
    //报到为3或3的倍数.要出局
    if(idx%3==0){
    System.out.println(arrs[i%len]+"出局.");
    arrs[i%len] = "OUT";
    count ++;
    }
    //报数器+1
    idx++;
    }
    }
      

  6.   

    楼主想加精吗?光凭这么一道简单算法的题是不成的啊。这个对于搞游戏方向的人来说就是小菜一碟连塞牙缝都不够。希望楼主更新试题,只有一道题太寂寞了。看了一下大家的解法,基本上的思想都是找一个数据容器循环做。最好考虑用java已经实装的数据结构,很实用的