Problem p01252 - Generation 2

Orig Description

Problem C: Alice and Bob
Alice and Bob are in love with each other, but they have difficulty going out on a date - Alice is a very
busy graduate student at the ACM university.
For this reason, Bob came to the ACM university to meet her on a day. He tried to reach the meeting
spot but got lost because the campus of the university was very large. Alice talked with him via mobile
phones and identified his current location exactly. So she told him to stay there and decided to go to the
place where she would be visible to him without interruption by buildings.
The campus can be considered as a two-dimensional plane and all buildings as rectangles whose edges
are parallel to x-axis or y-axis. Alice and Bob can be considered as points. Alice is visible to Bob if the
line segment connecting them does not intersect the interior of any building. Note that she is still visible
even if the line segment touches the borders of buildings.
Since Alice does not like to walk, she wants to minimize her walking distance. Can you write a program
that finds the best route for her?
Figure 1: Example Situation
Input
The input contains multiple datasets. The end of the input is indicated by a line containing a single zero.
Each dataset is formatted as follows.
      N
      x11 y11 x12 y12
      x21 y21 x22 y22
      ...
      xN1 yN1 xN2 yN2
      Ax Ay Bx By
N (0 < N ≤ 30) is the number of buildings. The i-th building is given by its bottom left corner (xi1 , yi1)
and up right corner (xi2, yi2 ). (Ax, Ay) is the location of Alice and (Bx, By) is that of Bob. All integers xi1, yi1, xi2, yi2, Ax, Ay, Bx and By are between -10000 and 10000, inclusive. You may assume that no building
touches or overlaps other buildings.
Output
For each dataset, output a separate line containing the minimum distance Alice has to walk.
The value may contain an error less than or equal to 0.001. You may print any number of digits after the
decimal point.
Sample Input
1
3 3 7 7
2 2 8 2
2
2 5 5 9
6 1 9 5
1 5 10 5
2
2 1 3 2
2 3 3 4
1 1 4 4
1
3 3 7 7
1 5 9 5
1
3 3 7 7
1 5 8 5
1
3 3 7 7
1 5 10 5
0
Output for the Sample Input
0.000
0.000
0.000
5.657
6.406
4.992

Extracted Specification

An integer N (0 < N ≤ 30), representing some quantity or size.
N lines follow, each containing four integers x1, y1, x2, y2. Each integer x1, y1, x2, y2 is between -10000 and 10000, inclusive.
A line containing four integers Ax, Ay, Bx, By. Each integer Ax, Ay, Bx, By is between -10000 and 10000, inclusive.

### Example Input:

```
2
2 5 5 9
6 1 9 5
1 5 10 5
```

### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, List[Tuple[int, int, int, int]], Tuple[int, int, int, int]]]):
    '''
    inputs: a list of tuples where each tuple contains:
        - an integer N
        - a list of N tuples, each containing four integers (x1, y1, x2, y2)
        - a tuple containing four integers (Ax, Ay, Bx, By)
    '''

Test Case Generator

Sure, I can help you with a test case generator for the "Alice and Bob" problem. Let's write a Python function that generates random test cases based on the given constraints.

Here is the test case generator:

```python
import random

def generate_building():
    x1 = random.randint(-10000, 10000)
    y1 = random.randint(-10000, 10000)
    x2 = random.randint(x1 + 1, 10001)  # Ensure x2 > x1
    y2 = random.randint(y1 + 1, 10001)  # Ensure y2 > y1
    return (x1, y1, x2, y2)

def tcgen():
    datasets = []
    while True:
        N = random.randint(1, 30)  # Number of buildings
        buildings = [generate_building() for _ in range(N)]
        
        Ax = random.randint(-10000, 10000)
        Ay = random.randint(-10000, 10000)
        Bx = random.randint(-10000, 10000)
        By = random.randint(-10000, 10000)
        
        dataset = {
            'N': N,
            'buildings': buildings,
            'Alice': (Ax, Ay),
            'Bob': (Bx, By)
        }
        datasets.append(dataset)
        
        # Randomly decide whether to stop
        if random.random() < 0.1:
            break
    
    return datasets

# Example usage
datasets = tcgen()
for dataset in datasets:
    print(dataset['N'])
    for building in dataset['buildings']:
        print(f"{building[0]} {building[1]} {building[2]} {building[3]}")
    print(f"{dataset['Alice'][0]} {dataset['Alice'][1]} {dataset['Bob'][0]} {dataset['Bob'][1]}")
print(0)
```

This function generates multiple datasets until it randomly decides to stop (with a 10% chance to stop after each dataset). Each dataset contains:

1. An integer \(N\) (1 ≤ \(N\) ≤ 30), representing the number of buildings.
2. Coordinates for each building in the form of four integers: \(x1, y1, x2, y2\), ensuring that \(x2 > x1\) and \(y2 > y1\).
3. Coordinates for Alice (\(Ax, Ay\)) and Bob (\(Bx, By\)) chosen randomly within the defined range.

The output ends with a single zero as required by the problem statement.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    while True:
        N = int(fh.readline().strip())
        if N == 0:
            break
        buildings = []
        for _ in range(N):
            x1, y1, x2, y2 = map(int, fh.readline().strip().split())
            buildings.append((x1, y1, x2, y2))
        Ax, Ay, Bx, By = map(int, fh.readline().strip().split())
        datasets.append((N, buildings, (Ax, Ay), (Bx, By)))
    return datasets