买彩票保证不赔本的最小花费
2019/03/10    

买彩票保证每次买彩票后如果中奖则不赔本的最小花费

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    </body>
    <script type="text/javascript">
    var countCurrPay = function(n){
        var orderCurr = n;//n本次是第几次购买
        var SumBefore = 0;//之前总花费
        var payCurr = 0;//本次需要花费金额
        for (var i = 1; i < orderCurr; i++) {
            var sumCurr = SumBefore*2/3;
            if(sumCurr==0){
                sumCurr = 2;
            }
            if(Math.ceil(sumCurr)%2==1){
                sumCurr = Math.ceil(sumCurr)+1;
            }else{
                sumCurr = Math.ceil(sumCurr);
            }
            SumBefore = SumBefore + sumCurr;
        }

        payCurr = Math.ceil(SumBefore*2/3)
        if(payCurr==0){
            payCurr = 2;
        }
        if(Math.ceil(payCurr)%2==1){
            payCurr = Math.ceil(payCurr)+1;
        }else{
            payCurr = Math.ceil(payCurr);
        }
        return {SumBefore:SumBefore,payCurr:payCurr,allPay:SumBefore+payCurr};
    }
    console.log(countCurrPay(15))
    </script>
</html>

每注两元,中奖的话19.4,保本不赔的卖法

  var countCurrPay = function (n) {
      var orderCurr = n; //n本次是第几次购买
      var SumBefore = 0; //之前总花费
      var payCurr = 0; //本次需要花费金额
      for (var i = 1; i < orderCurr; i++) {
          var sumCurr = SumBefore * 2 / 17.4;
          if (sumCurr == 0) {
              sumCurr = 2;
          }
          if (Math.ceil(sumCurr) % 2 == 1) {
              sumCurr = Math.ceil(sumCurr) + 1;
          } else {
              sumCurr = Math.ceil(sumCurr);
          }
          SumBefore = SumBefore + sumCurr;
      }

      payCurr = Math.ceil(SumBefore * 2 / 17.4)
      if (payCurr == 0) {
          payCurr = 2;
      }
      if (Math.ceil(payCurr) % 2 == 1) {
          payCurr = Math.ceil(payCurr) + 1;
      } else {
          payCurr = Math.ceil(payCurr);
      }
      return {
          SumBefore: SumBefore,
          payCurr: payCurr,
          allPay: SumBefore + payCurr
      };
  }
  console.log(countCurrPay(15))