首页 > 微信 > 详细

微信红包算法

时间:2017-02-28 00:50:02      阅读:215      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
using namespace std;



int main(void)
{
    int total = 10;
    int num = 8;
    int minuim = 0.01;
    
    srand (time(NULL));
    for(int i = 1; i< num; i++){
        float safe = (total - (num - i) * minuim)*1.0/(num - i);
        float money = (rand() %(int) (safe*100 - minuim* 100 ) + minuim * 100) * 1.0 / 100;
        cout << i <<" " << " money = "<< money << " res = "<< total - money <<endl;
        total -= money;
    }
    cout << 8 << " " << " money = "<< total  << " res = "<< 0 <<endl;


}

 

微信红包算法

原文:http://www.cnblogs.com/willwu/p/6476785.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!