"Algorithm" Statistics QQ day per second online number _ algorithm

Source: Internet
Author: User

"Problem" in order to count the number of online users of QQ per second in a day, each time a user offline will generate a record to the file: There are three fields in the record (on-line time, offline time, user name), time in seconds. Now that you have a file that contains the N records generated on that day (n is very large), design an algorithm that counts the number of online users per second of the day based on N Records. (0<= online time & lt; <=24*3600 time)

"Train of thought" create an array change[24*3600] used to record a day, the user changes per second, in the first I second on-line one person change[i]++, in the second line one person change[i]--,change[i] if is positive, This second line is larger than the number of people on the line, and vice versa. Create a online[24*3600] to record the number of people online per second, online[0] = 0 for No. 0 seconds online number 0, calculation method is online[n] = online[n-1] + change[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.