1271 advertising system

Source: Internet
Author: User
Description

An advertisement channel adopts a new advertising system. Each advertisement has a given value. The system always selects the most valuable advertisement from the existing one for broadcasting. The system receives a new advertisement every second from the start of the operation. The advertisement will be changed only when the value of the new advertisement is greater than that of the original one.

Now, the value of the advertisement received within n seconds starting from the system is presented in chronological order. It is required to calculate the expected number of actually played ads and the number of played ads for the ad channel during this period.

Input

The first line is an integer T, indicating that there are T groups of data:
There are two rows for each data set: the first row is a positive integer n (n ≤ 1,000,000) indicating the system running time, and the second row has n integers, the number of I represents the value of the second when an advertisement is received.

Output

For each group of test data, two rows are output: the first row is an integer representing the number of actually played ads, and the second row is a real number representing the expected number of played ads (three decimal places are expected ).

Sample Input
21105448456 2746865872 354878401
Sample output
11.00011.500

simple question simulation and expectation

 # include 
   
     int main () {int N; int I, j; int X; long int now; int count; long int y; double total; int K; scanf ("% d", & N); for (I = 0; I 
    
      now) {now = y; count ++ ;}} printf ("% d \ n", count); Total = 0; For (k = 1; k <= X; k ++) Total + = (double) (1)/K; printf ("%. 3lf \ n ", total);} return 0 ;}
    
   

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.