Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2014 /quals /square_detector.html
wjomlex's picture
2014 Problems
718fd53 verified
<p>
You want to write an image detection system that is able to recognize different geometric shapes.
In the first version of the system you settled with just being able to detect filled squares on a grid.</p>
<p>
You are given a grid of <strong>N</strong>&times;<strong>N</strong> square cells. Each cell is either white or black. Your task is to detect whether all the black cells form a square shape.
</p>
<h3>Input</h3>
<p>
The first line of the input consists of a single number <strong>T</strong>, the number of test
cases.
</p>
<p>
Each test case starts with a line containing a single integer <strong>N</strong>. Each of the subsequent <strong>N</strong> lines contain <strong>N</strong> characters. Each character is either "." symbolizing a white cell, or "#" symbolizing a black cell. Every test case contains at least one black cell.
</p>
<h3>Output</h3>
<p>
For each test case <strong>i</strong> numbered from 1 to <strong>T</strong>, output "Case #<strong>i</strong>: ", followed by <samp>YES</samp> or <samp>NO</samp> depending on whether or not all the black cells form a completely filled square with edges parallel to the grid of cells.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 20<br />
1 &le; <strong>N</strong> &le; 20
</p>
<h3>Example</h3>
<p> Test cases 1 and 5 represent valid squares. Case 2 has an extra cell that is outside of the square. Case 3 shows a square not filled inside. And case 4 is a rectangle but not a square.</p>