CF1926B.Vlad and Shapes

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vladislav has a binary square grid of n×nn \times n cells. A triangle or a square is drawn on the grid with symbols 1\texttt{1}. As he is too busy being cool, he asks you to tell him which shape is drawn on the grid.

  • A triangle is a shape consisting of kk (k>1k \gt 1) consecutive rows, where the ii-th row has 2⋅i−12 \cdot i-1 consecutive characters 1\texttt{1}, and the central 1s are located in one column. An upside down triangle is also considered a valid triangle (but not rotated by 90 degrees).

Two left pictures contain examples of triangles: k=4k=4, k=3k=3. The two right pictures don't contain triangles.

  • A square is a shape consisting of kk (k>1k \gt 1) consecutive rows, where the ii-th row has kk consecutive characters 1\texttt{1}, which are positioned at an equal distance from the left edge of the grid.

Examples of two squares: k=2k=2, k=4k=4.

For the given grid, determine the type of shape that is drawn on it.

弗拉迪斯拉夫有一个 n×nn \times n 的二进制方格。格子上用符号 1\texttt{1} 绘制了一个三角形或一个正方形。由于他太忙于耍酷,他请你告诉他格子上绘制的是哪种图形。

  • 三角形是由 kk(k>1k > 1)个连续的行构成的图形,其中第 ii 行包含 2⋅i−12 \cdot i - 1 个连续的 1\texttt{1},且所有行的中心 1\texttt{1} 位于同一列。倒置的三角形也被视为合法的三角形(但不包括绕 90 度旋转的情形)。

左侧两张图是三角形的例子:k=4k=4、k=3k=3;右侧两张图不是三角形。

  • 正方形是由 kk(k>1k > 1)个连续的行构成的图形,其中第 ii 行包含 kk 个连续的 1\texttt{1},且这些 1\texttt{1} 到网格左边缘的距离在所有行中均相等。

两个正方形的例子:k=2k=2、k=4k=4。

对于给定的网格,请判断其上绘制的图形类型。

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases.

The first line of each test case contains a single integer nn (2≤n≤102 \leq n \leq 10) — the size of the grid.

The next nn lines each contain nn characters 0\texttt{0} or 1\texttt{1}.

The grid contains exactly one triangle or exactly one square that contains all the 1\texttt{1}s in the grid. It is guaranteed that the size of the triangle or square is greater than 11 (i.e., the shape cannot consist of exactly one 1).

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤102 \leq n \leq 10)—— 网格的大小。

接下来的 nn 行,每行包含 nn 个字符,每个字符为 0\texttt{0} 或 1\texttt{1}。

该网格中恰好包含一个三角形或恰好一个正方形,且该图形包含了网格中所有的 1\texttt{1}。保证该三角形或正方形的尺寸大于 11(即该图形不能仅由一个 1\texttt{1} 构成)。

输出格式

For each test case, output "SQUARE" if all the 1\texttt{1}s in the grid form a square, and "TRIANGLE" otherwise (without quotes).

对于每个测试用例,如果网格中所有的 \texttt{1} 构成一个正方形,则输出 "SQUARE";否则输出 "TRIANGLE"(不带引号)。

输入输出样例

  • 输入#1

    6
    3
    000
    011
    011
    4
    0000
    0000
    0100
    1110
    2
    11
    11
    5
    00111
    00010
    00000
    00000
    00000
    10
    0000000000
    0000000000
    0000000000
    0000000000
    0000000000
    1111111110
    0111111100
    0011111000
    0001110000
    0000100000
    3
    111
    111
    111

    输出#1

    SQUARE
    TRIANGLE
    SQUARE
    TRIANGLE
    TRIANGLE
    SQUARE

输入解题思路,AI测评打分。不知道怎么写?

首页