A. Table----思维题
来源:互联网 发布:dc 大事件 知乎 编辑:程序博客网 时间:2024/05/17 21:44
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.
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 aijequals 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.
Print a single number — the minimum number of operations Simon needs to carry out his idea.
3 30 0 00 1 00 0 0
4
4 30 0 00 0 11 0 00 0 0
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).
题目链接:http://codeforces.com/contest/359/problem/A
题目的意思是说n * m的格子,每次取标记为1的点与一个角的矩形区域涂色,问最少需要多少步将这n*m个格子涂完(3 ≤ n, m ≤ 50,4个角不会出现1。
思路很简单,靠边两次,不靠边四次。
代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int main(){ int n,m,c; scanf("%d%d",&n,&m); bool flag=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ scanf("%d",&c); if((i==1||i==n||j==1||j==m)&&c==1) flag=1; } if(flag){ printf("2\n"); } else{ printf("4\n"); } return 0;}
- A. Table----思维题
- CodeForces 359A - Table(思维)
- Table Decorations(思维题)
- codeforces 359A- Table(简单思维)
- codeforces 577A Multiplication Table【思维】
- Codeforces--140A--New Year Table(思维)
- CodeForces 478C Table Decorations 思维题
- CodeForces - 417A(思维题)
- Codeforces 424A (思维题)
- A. Table
- A - Table
- table a
- A - Again Twenty Five!【思维题】
- A. Dima and Guards 【思维 好题】
- Code Forces 612A-----思维题
- Code forces 348A-----思维题
- CodeForces 714A 思维题 C
- A. Alyona and copybooks--思维水题
- php 提高效率的要点
- Android开发 第三课 使用TextView实现跑马灯效果
- POJ 2955:Brackets(区间DP)
- execute immediate的简单用法(oracle)
- Android 原生ExoPlayer 解析
- A. Table----思维题
- 从技术原理上解释火狐启动速度慢的原因
- hdu 1068 最大独立集
- LightOJ1370 Bi-shoe and Phi-shoe
- 快速排序,快速搞定
- 栈的基本功能实现(C语言)
- ASCII码一览表
- lniux svn清除和重新设置 小知识
- HDU 6503 TrickGCD