Questions about an algorithm for regular ticket swiping

Source: Internet
Author: User
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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.