An algorithm problem about regular ticket swiping: The scenario is as follows: cast N tickets in a certain period of time, for example, set up to brush 2000 tickets per hour! Then, they will be voted multiple times in an hour, and the number of votes each time is random (of course, the total number of votes cannot exceed 2000 as mentioned above ), how can we break it down into individual tasks. For example: 1. & nbsp; an algorithm problem about regular ticket swiping for 5 votes cast
The scenario for a regular ticket Flushing is as follows:
Cast N votes in a certain period of time, such as setting up 2000 votes per hour! Then, they will be voted multiple times in an hour, and the number of votes each time is random (of course, the total number of votes cannot exceed 2000 as mentioned above ), how can we break it down into individual tasks.
For example:
1. vote for 5
2. 7 votes
3. 200 votes
4. 10 votes
5 .....
Place N points.
Thank you! Share:
------ Solution --------------------
Ideas
Total = 2000; // total
$ Num = 20; // batch count
For ($ I = 0; $ I <$ num; $ I ++ ){
If ($ total ){
$ N = $ I + 1 = $ num? $ Total: rand (0, $ total * ($ I + 1)/$ num );
Echo $ n, PHP_EOL;
$ Total-= $ n;
}
}