腾讯微信红包算法

const-string v0, "this is a test"  
  
    const/16 v1, 0x3e8  
  
    invoke-static {p0, v0, v1}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;  
  
    move-result-object v0  
  
    invoke-virtual {v0}, Landroid/widget/Toast;->show()V


const-stringv0,"HelloWorld.SmaliHere"const/4v1,0x1 invoke-static{p0,v0,v1},\ Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast; move-result-objectv0 invoke-virtual{v0},Landroid/widget/Toast;->show()V



public static void main(String[] args) {

                double money; // 红包总金额
                int people; // 抢红包总人数
                double min_money;
                // 控制不能让每一个人抢到的是0元

                money = 10;
                people = 4;
                min_money = 0.01;

                for (int i = 0; i < people - 1; i++) {
                        int k = i + 1;
                        double safe_money = (money - (people - k) * min_money)
                                        / (people - k);
                        double tmp_money = (Math.random()
                                        * (safe_money * 100 - min_money * 100) + min_money * 100) / 100;
                        money = money - tmp_money;
                        System.out.format("第 %d 个红包: %.2f 元,剩下: %.2f 元\n", k, tmp_money,
                                        money);
                }
                System.out.format("第 %d 个红包: %.2f 元,剩下: 0 元\n", people, money);
        }

你可能感兴趣的:(算法)