CF 102697010 - Points per Game

The problem asks us to calculate a basketball player's current points per game. The input gives the total number of points scored so far and the total number of games played so far.

CF 102697010 - Points per Game

Rating: -
Tags: -
Solve time: 45s
Verified: yes

Solution

Problem Understanding

The problem asks us to calculate a basketball player's current points per game. The input gives the total number of points scored so far and the total number of games played so far. The required output is the average number of points scored in one game, computed as points divided by games.

The constraints are small enough that the algorithmic challenge is not about efficiency but about performing the calculation correctly. Since only two integers are processed, even a constant time solution is more than sufficient. The main concern is preserving the precision of the division. Integer division would discard the fractional part, so the calculation must be done using floating point arithmetic.

The most common mistakes come from treating the values as integers or formatting the answer unnecessarily. For example, if the input is:

78
7

the correct output is:

11.142857142857142

A careless implementation using integer division would output 11, losing the decimal part completely.

Another edge case is when the number of points is smaller than the number of games. For example:

5
10

The correct output is:

0.5

An implementation that assumes the answer is always greater than one, or that converts the result back to an integer, would produce an incorrect value.

Approaches

A direct brute force approach would try to simulate games and count points in each game before calculating the average. That approach is unnecessary because the problem already provides the total points and total games. If there were many games, simulating every game would require storing or processing information that does not exist in the input and would not improve the result.

The key observation is that points per game is simply the ratio of two totals. There is no hidden structure to discover, no searching, and no iteration required. The entire task is reduced to reading two numbers and performing one floating point division.

The brute force idea fails because it solves a more detailed version of the problem than required. The observation that only the final totals matter lets us replace any simulation with a single arithmetic operation.

Approach Time Complexity Space Complexity Verdict
Brute Force O(g) O(1) Unnecessary
Optimal O(1) O(1) Accepted

Algorithm Walkthrough

  1. Read the total points scored by the player and store it as an integer. Read the total number of games played and store it as another integer. These two values contain all the information needed for the calculation.
  2. Divide the total points by the total games using floating point division. The division must preserve the decimal portion because points per game is not necessarily a whole number.
  3. Print the resulting value directly. The required output accepts the normal floating point representation, so no manual rounding is needed.

Why it works:

The definition of points per game is the total points divided by the total games played. The algorithm performs exactly this operation using the two given totals. Since no other information affects the average, the computed value is always the required answer.

Python Solution

import sys
input = sys.stdin.readline

def solve():
    p = int(input())
    g = int(input())
    print(p / g)

if __name__ == "__main__":
    solve()

The solution reads the two input values separately because each value appears on its own line. The expression p / g uses Python's floating point division, unlike integer division, so values after the decimal point are preserved.

No special handling is required for overflow because Python integers can grow beyond fixed integer limits, and the calculation only uses two numbers. The program also avoids formatting the answer because the judge accepts the standard decimal representation produced by Python.

Worked Examples

For the first example:

78
7

the execution looks like this:

Step Points Games Calculation Result
Read input 78 7
Divide 78 7 78 / 7 11.142857142857142
Print 78 7 11.142857142857142

This trace shows that the answer comes directly from the mathematical definition. No intermediate simulation is needed.

For another example:

10
4

the execution is:

Step Points Games Calculation Result
Read input 10 4
Divide 10 4 10 / 4 2.5
Print 10 4 2.5

This example confirms that fractional answers are valid and must not be truncated.

Complexity Analysis

Measure Complexity Explanation
Time O(1) Only two numbers are read and one division is performed.
Space O(1) The program stores only the two input values.

The solution easily fits the given limits because its work does not depend on the size of the numbers beyond the cost of reading and dividing them.

Test Cases

import sys
import io

def solution(inp: str) -> str:
    old_stdin = sys.stdin
    sys.stdin = io.StringIO(inp)
    try:
        p = int(sys.stdin.readline())
        g = int(sys.stdin.readline())
        return str(p / g) + "\n"
    finally:
        sys.stdin = old_stdin

# provided samples
assert solution("78\n7\n") == "11.142857142857142\n", "sample 1"
assert solution("89\n15\n") == "5.933333333333333\n", "sample 2"

# custom cases
assert solution("1\n1\n") == "1.0\n", "minimum values"
assert solution("0\n5\n") == "0.0\n", "zero points"
assert solution("100\n100\n") == "1.0\n", "equal values"
assert solution("5\n10\n") == "0.5\n", "fraction smaller than one"
Test input Expected output What it validates
1 and 1 1.0 Checks the smallest normal calculation.
0 and 5 0.0 Checks that zero points are handled correctly.
100 and 100 1.0 Checks equal values.
5 and 10 0.5 Checks fractional results below one.

Edge Cases

When the points are not evenly divisible by the number of games, the answer contains a decimal part. For input:

78
7

the algorithm computes 78 / 7 as floating point division and prints the full decimal value. An integer division implementation would incorrectly lose the fractional component.

When the player has fewer points than games played, the average can be less than one. For input:

5
10

the algorithm computes 5 / 10, giving 0.5. It does not assume that the answer must be greater than one, so the result remains correct.

When the totals are equal, the division produces exactly one. For input:

100
100

the algorithm outputs 1.0. This confirms that the same calculation works for whole number answers as well as fractional ones.