他の人がお年玉を奪うので,お年玉のアルゴリズムを研究しましょう.

4195 ワード

 public static void main(String[] args) {
        //   
        int number = 10;
        //    
        float total = 100;
        float money;
        //    
        double min = 1;
        double max;
        int i = 1;
        List math = new ArrayList();
        DecimalFormat df = new DecimalFormat("###.##");
        while (i < number) {
            //             ,       ,            
            max = total - min * (number - i);
            int k = (int)(number - i) / 2;
            //                  
            if (number - i <= 2) {
                k = number - i;
            }
            //             
            max = max / k;
            //           ,        
            money = (int) (min * 100 + Math.random() * (max * 100 - min * 100 + 1));
            money = (float)money / 100;
            //      
            money = Float.parseFloat(df.format(money));
            total=(int)(total*100 - money*100);
            total = total/100;
            math.add(money);
            System.out.println(" " + i + "    " + money + "  " + total);
            i++;
            //            
            if (i == number) {
                math.add(total);
                System.out.println(" " + i + "    " + total + "  0");
            }
        }
//             
        System.out.println("       " + (math.indexOf(Collections.max(math)) + 1) + "      ");
    }

ブログの引っ越し、本文の新しい住所:http://www.zicheng.net/article/2