codeforces 359A Table
来源:互联网 发布:特效视频软件手机 编辑:程序博客网 时间:2024/06/17 19:19
Simon has a rectangular table consisting of n rows andm 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 thex-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, thei-th line contains m space-separated integers ai1, ai2, ..., aim. Ifaij 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.
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:
![](http://codeforces.com/predownloaded/fc/a8/fca83404eba90675a5ed3298f7f619b4011a40fe.png)
- 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:
![](http://codeforces.com/predownloaded/f5/59/f559fc83134107a34f05f21aedd174ac23340613.png)
- 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).
这是一个思维题,当这个矩阵的边上有1的时候,就只需要2步,不然的话就需要4步
#include<bits/stdc++.h>using namespace std;int mmap[51][51];int main(){int n,k;while(cin>>n>>k){int flag=0;for(int i=0;i<n;i++){for(int j=0;j<k;j++){scanf("%d",&mmap[i][j]);if(mmap[i][j]==1){if(i==0||i==n-1||j==0||j==k-1) flag=1;}}}if(flag) cout<<2<<endl;else cout<<4<<endl;}}
- CodeForces 359A Table
- codeforces 359A Table
- CodeForces 359A - Table(思维)
- Codeforces —— 359A Table
- codeforces 359A- Table(简单思维)
- CodeForces 577A - Multiplication Table
- Codeforces 582A GCD Table
- codeforces 582A GCD Table
- codeforces 577A Multiplication Table
- Codeforces 582A:GCD Table
- Codeforces 577A Multiplication Table
- codeforces 582A GCD Table
- CodeForces 266A Stones on the Table
- Codeforces Round #209 (Div. 2) A. Table
- Codeforces 361A Levko and Table
- [Codeforces] 361A - Levko and Table
- CodeForces-266A-Stones on the Table
- CodeForces-552A - Vanya and Table
- 初识JavaScript(1)
- HDU6180-Schedule
- 元素(块、行内、行内块
- ubuntu安装mysql可视化工具MySQL-workbench及简单操作
- jdk安装与配置
- codeforces 359A Table
- 初次接入Spring-001
- caffe\tesorflow提供服务
- CUDA编程学习一
- iOS面试题宝典(-)
- java动态代理(二)
- 浮动
- 剑指offer(十四)链表中倒数第k个结点
- AngularJS +Ionic 移动端开发 一