Orig Description
Problem B: Cubes Without Holes
There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure.
Then, holes are made in the cube by piercing from the marked surface to the opposite surface horizontally or vertically, as shown in the figure (right) above.
Your task is to create a program that reads n and the position of the marks, and counts the number of small cubes without holes.
Input
The input consists of multiple datasets. Each dataset is given in the following format:
n h
c1 a1 b1
c2 a2 b2
.
.
.
ch ah bh
h is an integer that indicates the number of marks. Following h lines specify the positions of the marks. To specify the position of the marks, we use the coordinate system shown in the figure below. (x, y, z) = (1, 1, 1) indicates the small cube at the lower left rear, and (x, y, z) = (n, n, n) indicates the small cube at the upper right front.
ci is a string that indicates the plane on which the i-th mark is placed. ci is either "xy", "xz", or "yz", which respectively indicate that the i-th mark is on the xy-plane, xz-plane, or yz-plane.
ai and bi indicate the coordinates on the plane indicated by ci. When the plane is xy-plane, xz-plane, or yz-plane, ai and bi respectively indicate the coordinates of the plane (x, y), (x, z), or (y, z). For example, in the figure above, the values of ci, ai, and bi for marks A, B, and C are "xy 4 4", "xz 1 2", and "yz 2 3", respectively.
When both n and h are 0, it indicates the end of the input.
It can be assumed that n ≤ 500 and h ≤ 200.
Output
For each dataset, output the number of small cubes without holes in one line.
Sample Input
4 3
xy 4 4
xz 1 2
yz 2 3
4 5
xy 1 1
xy 3 3
xz 3 3
yz 2 1
yz 3 3
0 0
Output for the Sample Input
52
46
Extracted Specification
An integer n (0 ≤ n ≤ 500), representing some quantity or size.
An integer h (0 ≤ h ≤ 200), representing the number of subsequent lines.
h lines follow, each containing:
- A string ci from the set {"xy", "xz", "yz"}.
- Two integers ai and bi, where 1 ≤ ai, bi ≤ n.
### Example Input:
```
4 3
xy 4 4
xz 1 2
yz 2 3
```
### Function Signature:
Write a function f(inputs) that takes in the input.
```python
from typing import List, Tuple
def f(inputs: List[Tuple[int, int, List[Tuple[str, int, int]]]]):
'''
inputs: a list of tuples, where each tuple contains:
- an integer n
- an integer h
- a list of tuples, each containing:
- a string ci
- an integer ai
- an integer bi
'''
```
Test Case Generator
Certainly! Below is a test case generator for the problem "Cubes Without Holes". This generator will create random values for `n`, `h`, and the positions of marks.
We'll use Python for the implementation of the test case generator:
```python
import random
def tcgen():
datasets = []
while True:
# Generate n and h
n = random.randint(1, 500)
h = random.randint(0, 200)
if n == 0 and h == 0:
break
marks = []
for _ in range(h):
plane = random.choice(["xy", "xz", "yz"])
a = random.randint(1, n)
b = random.randint(1, n)
marks.append(f"{plane} {a} {b}")
datasets.append((n, h, marks))
# Randomly decide to stop generating more datasets
if random.random() < 0.1:
break
# Ensure the last dataset is "0 0"
datasets.append((0, 0, []))
return datasets
# Function to print the generated test cases in the required format
def print_test_cases(datasets):
for dataset in datasets:
n, h, marks = dataset
print(f"{n} {h}")
for mark in marks:
print(mark)
if n == 0 and h == 0:
break
# Generate and print test cases
datasets = tcgen()
print_test_cases(datasets)
```
### Explanation:
- **tcgen function**:
- Generates random `n` (1 ≤ `n` ≤ 500).
- Generates random `h` (0 ≤ `h` ≤ 200).
- For each mark, randomly selects a plane (`"xy"`, `"xz"`, `"yz"`) and random coordinates within the range of `n`.
- Continues generating datasets until a stopping condition (1 in 10 chance after each dataset) is met, ensuring the last dataset is `0 0`.
- **print_test_cases function**:
- Prints each dataset in the format specified in the problem statement.
- Stops printing when `n` and `h` are `0`.
You can use this generator to produce multiple test cases for the problem. This way, you can test your solution more effectively.
Extract Arguments
def extract_arguments(fh):
data = []
while True:
n, h = map(int, fh.readline().strip().split())
if n == 0 and h == 0:
break
marks = []
for _ in range(h):
ci, ai, bi = fh.readline().strip().split()
marks.append((ci, int(ai), int(bi)))
data.append((n, h, marks))
return data