CF690B1.Recover Polygon (easy)

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.

Heidi knows that the lair can be represented as a rectangle on a lattice, with sides parallel to the axes. Each vertex of the polygon occupies an integer point on the lattice. For each cell of the lattice, Heidi can check the level of Zombie Contamination. This level is an integer between 0 and 4, equal to the number of corners of the cell that are inside or on the border of the rectangle.

As a test, Heidi wants to check that her Zombie Contamination level checker works. Given the output of the checker, Heidi wants to know whether it could have been produced by a single non-zero area rectangular-shaped lair (with axis-parallel sides).

僵尸正在它们的秘密巢穴中集结!海蒂将发起猛烈攻击,彻底消灭它们。但这里有一个小问题……在发动攻击之前,她需要知道巢穴的位置。而她所掌握的情报并不十分可靠。

海蒂知道,该巢穴可在格点上表示为一个矩形,其边与坐标轴平行。该矩形的每个顶点均位于格点的整数坐标上。对于格点上的每个单元格(cell),海蒂均可检测其“僵尸污染程度”(Zombie Contamination level)。该污染程度是一个介于 0 到 4 之间的整数,其值等于该单元格的四个角中位于矩形内部或边界上的角的个数。

作为一次测试,海蒂希望验证她的僵尸污染程度检测器是否工作正常。给定检测器的输出结果,海蒂想知道:该输出是否可能由某个面积非零、边与坐标轴平行的矩形巢穴产生?

输入格式

The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 50). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4.

Cells are given in the same order as they are shown in the picture above: rows go in the decreasing value of y coordinate, and in one row cells go in the order of increasing x coordinate. This means that the first row corresponds to cells with coordinates (1, N), ..., (N, N) and the last row corresponds to cells with coordinates (1, 1), ..., (N, 1).

每个测试用例的第一行包含一个整数 NN,表示格点网格的大小(5 ≤ N ≤ 505 \leq N \leq 50)。接下来的 NN 行每行包含 NN 个字符,描述格点中每个单元格的僵尸污染等级。每行的每个字符均为 00 到 44 之间的数字。

单元格的给出顺序与上图中所示顺序一致:行按 yy 坐标递减的顺序排列,而在同一行内,单元格按 xx 坐标递增的顺序排列。这意味着第一行对应坐标为 (1, N), …, (N, N)(1, N), \ldots, (N, N) 的单元格,而最后一行对应坐标为 (1, 1), …, (N, 1)(1, 1), \ldots, (N, 1) 的单元格。

输出格式

The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise.

输出的第一行应包含“Yes”,如果存在一个面积非零的矩形巢穴,其四个角均位于网格点上,且对该巢穴进行僵尸污染等级检测所得到的结果与输入中给出的结果一致;否则应包含“No”。

输入输出样例

  • 输入#1

    6
    000000
    000000
    012100
    024200
    012100
    000000

    输出#1

    Yes

说明/提示

The lair, if it exists, has to be rectangular (that is, have corners at some grid points with coordinates (_x_1, _y_1), (_x_1, _y_2), (_x_2, _y_1), (_x_2, _y_2)), has a non-zero area and be contained inside of the grid (that is, 0 ≤ _x_1 < _x_2 ≤ N, 0 ≤ _y_1 < _y_2 ≤ N), and result in the levels of Zombie Contamination as reported in the input.

如果藏身处存在,则必须是矩形(即其四个角位于某些网格点上,坐标分别为 (x1,y1)(x_1, y_1)、(x1,y2)(x_1, y_2)、(x2,y1)(x_2, y_1)、(x2,y2)(x_2, y_2)),面积非零,且完全包含在网格内部(即满足 0≤x1<x2≤N0 \le x_1 < x_2 \le N,0≤y1<y2≤N0 \le y_1 < y_2 \le N),并能产生输入中所报告的僵尸污染等级。

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

首页