A - Table
来源:互联网 发布:mac 16g内存 虚拟机 编辑:程序博客网 时间:2024/06/06 00:27
Description
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(x1, y1), an arbitrary corner of the table (x2, y2) and color all cells of the table (p, q), which meet both inequations: min(x1, x2) ≤ p ≤ max(x1, x2), min(y1, y2) ≤ q ≤ max(y1, y2).
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.
Input
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 ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
Output
Print a single number — the minimum number of operations Simon needs to carry out his idea.
Sample Input
3 30 0 00 1 00 0 0
4
4 30 0 00 0 11 0 00 0 0
2
这道题只要把题目读懂,基本就能做了,不要想得太复杂,画图就知道了,就给代码。
参考代码如下:
#include <stdio.h>int main(){ int n, m,i,j,a[100][100]={0}; while(scanf("%d%d",&n,&m)!=EOF) { bool flag=true; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { scanf("%d",&a[i][j]); if((i==1||j==1||i==n||j==m)&&a[i][j]) flag=false; } if(flag)printf("4\n"); else printf("2\n"); } return 0;}
- A. Table
- A - Table
- table a
- A CSS styled table
- Rename a Table
- jquery+table+td+a
- 10820 - Send a Table
- UVaOJ10820 - Send a Table
- A. New Year Table
- Send a Table
- A. Levko and Table
- Send a Table
- Send a Table
- A. Maximum in Table
- A. Maximum in Table
- A - Maximum in Table
- Send a Table
- 10820 - Send a Table
- C/C++中自动类型转换的规则
- 数据结构实验之求二叉树后序遍历和层次遍历
- nvidia developer tools
- STL之bitset
- 寒假训练--字典树--Message Flood
- A - Table
- ubuntu软件怎么安装 有那些安装方法 ?Ubuntu 软件安装详解!!
- 工程师制作:耳机放大器制作历程全解
- Phone List
- 友链博客列表
- 全程软件测试实践:从需求到运营
- 宏定义的黑魔法 - 宏菜鸟起飞手册
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 计算器