Orig Description
Convenience Store
To expand its business, the convenience store Seven-Eleven is considering opening its first store in Wakamatsu City. Since there are already many other convenience stores in Wakamatsu City, the location of the new store is likely to be the key to success. Under the premise of "customers will use the convenience store closest to their home area," Seven-Eleven plans to open a store at a location where "many customers are likely to use it."
Seven-Eleven divided the map of Wakamatsu City into congruent regular hexagons ("blocks") to understand the range covered by each existing convenience store. At this time, the city was divided into blocks so that at most one existing convenience store could be included in each block. Based on the number of blocks that need to be traversed to reach a convenience store from each block, the distance between the convenience store and each block is determined. Each block is considered to be covered by the convenience store that covers it with the shortest distance. The problem is to find the "blocks for which there are no existing convenience stores that cover as many blocks as possible" based on this map.
You are a programmer at Seven-Eleven, and you have been tasked with developing a program to calculate the maximum number of blocks that can be covered from all candidate locations based on the map divided into blocks and information about the candidate location of the new store.
The map divided into blocks of m × n is represented as shown in Figure 1. Blocks of hexagons are arranged horizontally in m rows and vertically in n columns, each represented by a coordinate (x, y). The left edge of odd-numbered rows is located just below the left edge of the row above it, and the left edge of even-numbered rows is located just below the left edge of the row above it. For example, coordinate (1, 1) represents the top-left block in Figure 1. Coordinate (1, 2) is located just below coordinate (1, 1), and coordinate (1, 3) is located just below coordinate (1, 2).
Figure 2 shows an example where there are six existing convenience stores, divided into a 6 × 6 map. Each convenience store is numbered in order from 1. When the blocks covered by each convenience store are colored by number, they are divided as shown in Figure 3. Blocks that are not colored, such as block (1, 4) and (2, 5), have two or more convenience stores that are closest, and cannot be determined which convenience store covers the block. For example, in the case of block (1, 4), the distance to convenience stores 4 and 5 is equal, and it is assumed that there is no convenience store that covers this block. The number of blocks covered by convenience store 4 is 5.
Suppose Seven-Eleven is considering locations (1, 3) and (5, 3) as candidate locations for the new store. If a store is located at (1, 3), it can cover three blocks (Figure 4). On the other hand, if a store is located at (5, 3), it can cover four blocks (Figure 5). Therefore, the maximum number of blocks that can be covered is 4.
The input consists of multiple datasets. The end of the input is indicated by
Extracted Specification
An integer m (1 ≤ m ≤ 50), representing some quantity or size.
An integer n (1 ≤ n ≤ 50), representing some quantity or size.
A 2D list B of size m × n, where each element is a character from the set {'.', '1', '2', ..., '9'}.
An integer k (1 ≤ k ≤ 10), representing the number of operations or queries.
A list of k tuples T, where each tuple contains two integers (x, y) (1 ≤ x ≤ m, 1 ≤ y ≤ n).
### Example Input:
```
6
6
......
.1.2..
.1....
.1..3.
.1....
......
2
1 3
5 3
```
### Function Signature:
Write a function f(m, n, B, k, T) that takes in the input.
def f(m: int, n: int, B: List[List[str]], k: int, T: List[Tuple[int, int]]):
'''
m: an integer
n: an integer
B: a 2D list of characters
k: an integer
T: a list of tuples
'''
Test Case Generator
Certainly! Here is a test case generator for the given competitive programming problem "Convenience Store":
```python
import random
def tcgen():
# Generate the map dimensions m and n
m = random.randint(1, 20) # Adjust the upper limit as per problem constraints
n = random.randint(1, 20) # Adjust the upper limit as per problem constraints
# Generate the number of existing convenience stores
num_stores = random.randint(1, min(m * n, 10)) # Ensuring at least one store and not more stores than blocks
# Generate the coordinates of the existing convenience stores
existing_stores = set()
while len(existing_stores) < num_stores:
x = random.randint(1, m)
y = random.randint(1, n)
existing_stores.add((x, y))
existing_stores = list(existing_stores)
# Generate the number of candidate locations
num_candidates = random.randint(1, min(m * n - num_stores, 10)) # Ensuring not to exceed the available blocks
# Generate the coordinates of the candidate store locations
candidate_locations = set()
while len(candidate_locations) < num_candidates:
x = random.randint(1, m)
y = random.randint(1, n)
if (x, y) not in existing_stores:
candidate_locations.add((x, y))
candidate_locations = list(candidate_locations)
return m, n, existing_stores, candidate_locations
# Example usage
for _ in range(5): # Generate 5 test cases
m, n, existing_stores, candidate_locations = tcgen()
print(f"Map dimensions: {m}x{n}")
print(f"Existing stores: {existing_stores}")
print(f"Candidate locations: {candidate_locations}")
print()
```
### Explanation
1. **Map Dimensions (m and n)**:
- The dimensions of the city map are generated with both values ranging between 1 and 20. These bounds can be adjusted according to the problem constraints.
2. **Number of Existing Convenience Stores**:
- A random number of stores is chosen between 1 and the minimum of \(m \times n\) and 10. This ensures that at least one store exists and does not exceed the number of blocks.
3. **Coordinates of Existing Stores**:
- Unique coordinates are generated for the existing stores until the desired number of stores is reached.
4. **Number of Candidate Locations**:
- A random number of candidate locations is chosen, ensuring that it does not exceed the number of available blocks after placing the existing stores.
5. **Coordinates of Candidate Stores**:
- Unique coordinates are generated for the candidate stores, ensuring no overlap with the existing stores.
The generated test cases provide various scenarios of map sizes, existing store placements, and candidate locations, facilitating thorough testing of the solution.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
m, n = map(int, fh.readline().strip().split())
if m == 0 and n == 0:
break
grid = []
for _ in range(m):
grid.append(list(map(int, fh.readline().strip().split())))
candidates = []
while True:
candidate = fh.readline().strip()
if candidate == "0 0":
break
candidates.append(tuple(map(int, candidate.split())))
datasets.append((m, n, grid, candidates))
return datasets
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# datasets = extract_arguments(fh)
# for dataset in datasets:
# f(dataset)