Problem p00864 - Generation 3

Orig Description

Problem A: Grey Area
Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the
world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is
a simple self-made histogram generator.
Figure 1 is an example of histogram automatically produced by his histogram.
A histogram is a visual display of frequencies of value occurrences as bars. In this example, values
in the interval 0-9 occur five times, those in the interval 10-19 occur three times, and 20-29
and 30-39 once each.
Dr. Grey’s histogram generator is a simple tool. First, the height of the histogram is fixed, that
is, the height of the highest bar is always the same and those of the others are automatically
adjusted proportionately. Second, the widths of bars are also fixed. It can only produce a
histogram of uniform intervals, that is, each interval of a histogram should have the same width
(10 in the above example). Finally, the bar for each interval is painted in a grey color, where
the colors of the leftmost and the rightmost intervals are black and white, respectively, and the
darkness of bars monotonically decreases at the same rate from left to right. For instance, in
Figure 1, the darkness levels of the four bars are 1, 2/3, 1/3, and 0, respectively.
In this problem, you are requested to estimate ink consumption when printing a histogram on paper. The amount of ink necessary to draw a bar is proportional to both its area and darkness.
Input
The input consists of multiple datasets, each of which contains integers and specifies a value
table and intervals for the histogram generator, in the following format.
n w
v1
v2
.
.
vn
n is the total number of value occurrences for the histogram, and each of the n lines following
the first line contains a single value. Note that the same value may possibly occur multiple
times.
w is the interval width. A value v is in the first (i.e. leftmost) interval if 0 ≤ v < w, the second
one if w ≤ v < 2w, and so on. Note that the interval from 0 (inclusive) to w (exclusive) should
be regarded as the leftmost even if no values occur in this interval. The last (i.e. rightmost)
interval is the one that includes the largest value in the dataset.
You may assume the following.
                                  1 ≤ n ≤ 100
                                  10 ≤ w ≤ 50
                                  0 ≤ vi ≤ 100 for 1 ≤ i ≤ n
You can also assume that the maximum value is no less than w. This means that the histogram
has more than one interval.
The end of the input is indicated by a line containing two zeros.
Output
For each dataset, output a line containing the amount of ink consumed in printing the histogram.
One unit of ink is necessary to paint one highest bar black. Assume that 0.01 units of ink per
histogram is consumed for various purposes except for painting bars such as drawing lines and
characters (see Figure 1). For instance, the amount of ink consumed in printing the histogram
in Figure 1 is:
Each output value should be in a decimal fraction and may have an error less than 10-5 .
Sample Input
3 50
100
0
100
3 50
100
100
50
10 10
1
2
3
4
5
16
17
18
29
30
0 0
Output for the Sample Input
0.51
0.26
1.4766666666666667

Extracted Specification

An integer \( n \) (1 ≤ \( n \) ≤ 100), representing some quantity or size.
An integer \( w \) (10 ≤ \( w \) ≤ 50), representing an interval width.
A list of \( n \) integers \( v \) (0 ≤ \( v_i \) ≤ 100), where each integer is a value.

### Example Input:

```
3 50
100
0
100
```

### Function Signature:
Write a function `f(inputs)` that takes in the input.
```python
def f(inputs: List[Tuple[int, int, List[int]]]):
    '''
    inputs: a list of tuples, each containing:
        - an integer n
        - an integer w
        - a list of n integers v
    '''
```

Test Case Generator

Certainly! Below is a Python function to generate test cases for the "Grey Area" problem. The function will generate random values following the constraints provided in the problem statement.

```python
import random

def tcgen():
    test_cases = []
    
    while True:
        # Generate n and w
        n = random.randint(1, 100)
        w = random.randint(10, 50)
        
        # Generate values v1, v2, ..., vn
        values = [random.randint(0, 100) for _ in range(n)]
        
        test_cases.append((n, w, values))
        
        # Randomly decide to stop adding more test cases
        if random.choice([True, False]):
            break
    
    # Append the end-of-input indicator
    test_cases.append((0, 0, []))
    
    return test_cases

# Example of how to use the test case generator
def print_test_cases(test_cases):
    for case in test_cases:
        n, w, values = case
        print(f"{n} {w}")
        for value in values:
            print(value)
    print("0 0")

# Generate and print test cases
test_cases = tcgen()
print_test_cases(test_cases)
```

### Explanation:
1. **Randomly generate `n` and `w`:**
   - `n` is the number of values and is randomly chosen between 1 and 100.
   - `w` is the interval width and is randomly chosen between 10 and 50.

2. **Generate `n` random values for the histogram:**
   - Each value `vi` is randomly chosen between 0 and 100.

3. **Add random stopping condition:**
   - Randomly decide whether to stop adding more test cases to simulate multiple datasets.

4. **Append the end-of-input indicator:**
   - The end of input is indicated by a line containing two zeros (`0 0`).

5. **Utility function `print_test_cases`:**
   - This function prints the test cases generated in the required format.

You can call the `tcgen()` function to generate test cases and use the `print_test_cases` function to print them in the correct format. The generated test cases will follow the constraints and structure as specified in the "Grey Area" problem statement.

Extract Arguments

def extract_arguments(fh):
    inputs = []
    while True:
        n, w = map(int, fh.readline().strip().split())
        if n == 0 and w == 0:
            break
        v = [int(fh.readline().strip()) for _ in range(n)]
        inputs.append((n, w, v))
    return inputs