CF359A.Table
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1), (n, 1), (1, m), (n, m).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (_x_1, _y_1), an arbitrary corner of the table (_x_2, _y_2) and color all cells of the table (p, q), which meet both inequations: min(_x_1, _x_2) ≤ p ≤ max(_x_1, _x_2), min(_y_1, _y_2) ≤ q ≤ max(_y_1, _y_2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.
西蒙有一张由 n 行 m 列构成的矩形表格。西蒙将表格的行从上到下编号,起始编号为 1;列从左到右编号,起始编号也为 1。我们将第 x 行、第 y 列的单元格记作数对 (x,y)。表格的四个角分别是单元格:(1,1)、(n,1)、(1,m)、(n,m)。
西蒙认为该表格中某些单元格是“好”的。此外,已知任意一个“好”单元格均不是表格的角。
初始时,表格中所有单元格均未着色。西蒙希望为表格的所有单元格着色。在一次操作中,他可以任选一个“好”单元格 (x1,y1) 和表格的一个角 (x2,y2),并将所有满足以下两个不等式的单元格 (p,q) 着色:
min(x1,x2)≤p≤max(x1,x2),min(y1,y2)≤q≤max(y1,y2).
请帮助西蒙!求出将表格所有单元格着色所需的最少操作次数。注意:一个单元格可以被多次着色。
输入格式
The first line contains exactly two integers n, m (3 ≤ n, m ≤ 50).
Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers _a__i_1, _a__i_2, ..., a__im. If a__ij equals zero, then cell (i, j) isn't good. Otherwise a__ij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
第一行包含恰好两个整数 n、m(3≤n,m≤50)。
接下来的 n 行描述表格的单元格。具体而言,第 i 行包含 m 个以空格分隔的整数 ai1, ai2, …, aim。若 aij 等于零,则单元格 (i, j) 不是“好”的;否则 aij 等于一。保证至少存在一个“好”的单元格。保证没有任何“好”的单元格位于角落。
输出格式
Print a single number — the minimum number of operations Simon needs to carry out his idea.
输出一个整数——西蒙实现其想法所需的最少操作次数。
输入输出样例
输入#1
3 3 0 0 0 0 1 0 0 0 0
输出#1
4
输入#2
4 3 0 0 0 0 0 1 1 0 0 0 0 0
输出#2
2
说明/提示
In the first sample, the sequence of operations can be like this:

- For the first time you need to choose cell (2, 2) and corner (1, 1).
- For the second time you need to choose cell (2, 2) and corner (3, 3).
- For the third time you need to choose cell (2, 2) and corner (3, 1).
- For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:

- For the first time you need to choose cell (3, 1) and corner (4, 3).
- For the second time you need to choose cell (2, 3) and corner (1, 1).
在第一个样例中,操作序列可以如下所示:

- 第一次需选择单元格 (2,2) 和角点 (1,1);
- 第二次需选择单元格 (2,2) 和角点 (3,3);
- 第三次需选择单元格 (2,2) 和角点 (3,1);
- 第四次需选择单元格 (2,2) 和角点 (1,3)。
在第二个样例中,操作序列可以如下所示:

- 第一次需选择单元格 (3,1) 和角点 (4,3);
- 第二次需选择单元格 (2,3) 和角点 (1,1)。
输入解题思路,AI测评打分。不知道怎么写?