CCC '05 S5 - Pinball Ranking

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 0.2s
Java 0.3s
Memory limit: 256M

Problem types
Canadian Computing Competition: 2005 Stage 1, Senior #5

Pinball is an arcade game in which an individual player controls a silver ball by means of flippers, with the objective of accumulating as many points as possible. At the end of each game, the player's score and rank are displayed. The score, an integer between 0 and 1\,000\,000\,000, is that achieved by the player in the game just ended. The rank is displayed as "r of n". n is the total number of games ever played on the machine, and r is the position of the score for the just-ended game within this set.

More precisely, r is one greater than the number of games whose score exceeds that of the game just ended.

Input Specification

You are to implement the pinball machine's ranking algorithm. The first line of input contains a positive integer, t, the total number of games played in the lifetime of the machine. t lines follow, given the scores of these games, in chronological order.

Output Specification

You are to output the average of the ranks up to an absolute error of 10^{-2} that would be displayed on the board.

At least one test case will have t \le 100. All test cases will have t \le 100\,000.

Sample Input

5
100
200
150
170
50

Sample Output

2.20

Explanation for Sample Output

The pinball screen would display (in turn):

1 of 1
1 of 2
2 of 3
2 of 4
5 of 5

The average rank is (1+1+2+2+5)/5 = 2.20.


Comments


  • 2
    Kirito  commented on Sept. 17, 2023, 2:33 p.m.

    Java time limit has been increased to 0.3s and submissions rejudged.


  • 0
    rnpmat08  commented on July 29, 2022, 3:01 a.m.

    I'm getting TLE (Time Limit Exceeded) and I don't know how to make my code run faster


  • 3
    maxcruickshanks  commented on April 21, 2022, 1:47 a.m.

    Since the data were not language friendly, the specificity for the answer has been updated (refer to the problem statement), and all submissions were rejudged.


  • 15
    Kuroba  commented on May 20, 2020, 12:36 a.m. edit 5

    If you find that you're WA on only test case 4, it's likely an issue with your rounding.

    The test data was generated with an implementation of round which rounds towards even, thus round(4.5) -> 4, but round(5.5) -> 6.

    Change your round function accordingly. In C/C++, you can just use rint() instead of std::round().

    In case you wanted to see what life was like before C++11: https://man7.org/linux/man-pages/man3/lrint.3.html


  • -4
    wleung_bvg  commented on May 7, 2020, 10:55 p.m. edit 2

    It appears that the statement rounded to two digits after the decimal is slightly misleading and should actually say truncated to two digits after the decimal. Most of the accepted solutions and the official CCC data incorrectly rounded in the 4th test case due to double precision issues.

    (For longer version, see comment edit history)


    • 15
      Kuroba  commented on May 20, 2020, 1:03 a.m. edit 3

      You're correct -- the test data is actually incorrect with respect to the problem statement: but it's not supposed to be truncation either.

      Before C++11 introduced std::round(), people had to implement their own round functions, or use rint/lrint, which reads your system state for the "rounding mode". The default rounding mode for IEEE 754 floating point operations is Banker's Rounding, which rounds halfway numbers to even integers. I believe this is the rounding used to generate the test case, which rounded 24794.5 to 24794.

      Note that this is not the behavior of std::round.

      EDIT: Looking at many of the other user submissions, many people are just using printf("%.2f", ans);. This just rounds the answer to two decimal places using rint as the backend I think.


  • 2
    Lemonsity  commented on Dec. 2, 2018, 9:16 p.m.

    Can we assume no two input are the same?

    If they are the same, what should I output?


    • 4
      Relativity  commented on Dec. 3, 2018, 11:58 p.m.

      Inputs are not necessarily distinct


  • -7
    septence123  commented on Jan. 6, 2017, 4:48 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -5
      ZQFMGB12  commented on Jan. 6, 2017, 5:25 a.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


  • -7
    MathBunny123  commented on Jan. 30, 2016, 3:11 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -2
      jeffreyxiao  commented on Jan. 30, 2016, 4:03 a.m. edited

      Your solution is \mathcal O(N^2 \log N) because insertion into an ArrayList at an arbitrary position takes \mathcal O(N) time.


      • -3
        MathBunny  commented on Jan. 30, 2016, 5:10 p.m.

        Really? Okay thanks a lot!


  • -25
    bobhob314  commented on Jan. 24, 2015, 2:20 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -20
      Sentient  commented on Jan. 24, 2015, 4:00 p.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


      • -18
        lolzballs  commented on March 19, 2015, 3:53 p.m.

        This comment is hidden due to too much negative feedback. Show it anyway.


        • -15
          quantum  commented on March 19, 2015, 4:04 p.m.

          This comment is hidden due to too much negative feedback. Show it anyway.


        • -18
          FatalEagle  commented on March 19, 2015, 3:59 p.m.

          This comment is hidden due to too much negative feedback. Show it anyway.