Orig Description
Problem
Koto City is a famous city with a grid-like road system, as shown in the figure below. Roads extending north-south and east-west are arranged at intervals of 1 km. Assume that Koto Station located at the southwesternmost intersection of Koto City is (0,0), and the position reached by going x km east and y km north from there is expressed as (x,y) (0 ≤ x,y).
In anticipation of an increase in tourists due to the Olympics to be held in five years, the city has decided to build a new subway line starting from Koto Station. Currently, a plan is being made to lay rails from Koto Station to Shin-Koto Station, which will be newly built as the next station from Koto Station. The rails will be laid straight from Koto Station to Shin-Koto Station. Therefore, the length of the rails is √(x2+y2) when the location of Shin-Koto Station is expressed as (x,y). The cost of laying rails is required as much as the length of the rails laid, even if the length of the rails is a decimal such as 1.5 km.
The location (x,y) of Shin-Koto Station has not yet been determined, and it is planned to be located in a place that satisfies the following conditions:
It is an intersection. That is, x and y are integers, respectively.
The shortest distance walked along the road from Koto Station is exactly D, that is, x + y = D.
Among those that satisfy the above two conditions, choose the location of Shin-Koto Station so that the difference between the budget for rails that the city specifies and the cost of the rails |√(x2+y2) - E| is minimized. Here, |A| represents the absolute value of A. Your task is to create a program that outputs the cost difference between the cost of laying the rails and the budget when Shin-Koto Station is built as described above.
Input
The input is composed of multiple data sets, and the number of data sets included in one input is up to 100. The format of each data set is as follows:
D E
D (1 ≤ D ≤ 100) is an integer representing the shortest distance walked along the road from Koto Station to Shin-Koto Station. E (1 ≤ E ≤ 100) is an integer representing the budget for rail construction.
The end of the input is indicated by a line consisting of two zeros separated by a space.
Output
For each data set, output the difference between the cost of laying the rails when the rails are laid as described above and the budget in one line. There should be no absolute error greater than 10-3. If you do not output a newline at the end of each line or output unnecessary characters, it will be judged as incorrect answer, so be careful.
Sample Input
2 1
7 5
7 6
7 7
76 5
8 41
0 0
Output for Sample Input
0.4142135624
0
0.0827625303
0
48.7401153702
33
Hint
For the first data set, the intersections that are 2 km along the road from Koto Station are expected to be candidates for the location of Shin-Koto Station
Extracted Specification
An integer D (1 ≤ D ≤ 100), representing some quantity.
An integer E (1 ≤ E ≤ 100), representing some budget.
The input is a list of tuples (D, E) with a maximum length of 100.
The end of the input is indicated by a tuple (0, 0).
### Example Input:
```
2 1
7 5
7 6
7 7
76 5
8 41
0 0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, int]]):
'''
inputs: a list of tuples, where each tuple contains two integers
'''
Test Case Generator
Sure, let's create a test case generator for the given problem statement. The test cases will be based on the constraints provided:
1. \(D\) should be an integer between 1 and 100 inclusive.
2. \(E\) should be an integer between 1 and 100 inclusive.
3. We need multiple data sets, up to 100 in one input.
4. The end of the input should be indicated by a line consisting of two zeros separated by a space.
Here's the test case generator:
```python
import random
def tcgen(num_tests=100):
test_cases = []
for _ in range(num_tests):
D = random.randint(1, 100)
E = random.randint(1, 100)
test_cases.append((D, E))
# Append the terminating line "0 0"
test_cases.append((0, 0))
return test_cases
# Example usage
if __name__ == "__main__":
test_cases = tcgen()
for D, E in test_cases:
print(D, E)
```
### Explanation:
1. **Random Selection of \(D\) and \(E\)**:
- We generate random integers for \(D\) and \(E\) within their respective ranges (1 to 100).
2. **Appending the Termination Line**:
- We append the line `(0, 0)` at the end to indicate the end of the input.
3. **Output Format**:
- Each test case is printed in the required format with \(D\) and \(E\) separated by a space.
### Example Output:
```
45 23
12 98
99 45
...
0 0
```
You can adjust `num_tests` to generate fewer or more test cases as needed, with a maximum of 100 as per the problem's constraints.
Extract Arguments
def extract_arguments(fh):
inputs = []
while True:
line = fh.readline().strip()
if line == "0 0":
break
D, E = map(int, line.split())
inputs.append((D, E))
return inputs