B. Square Filling
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two matrices A

and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0

.

You may perform some operations with matrix B

. During each operation, you choose any submatrix of B having size 2×2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1≤x<n and 1≤y<m, and then set Bx,y, Bx,y+1, Bx+1,y and Bx+1,y+1 to 1

.

Your goal is to make matrix B

equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B

.

Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B

equal to A

. Note that you don't have to minimize the number of operations.

Input

The first line contains two integers n

and m (2≤n,m≤50

).

Then n

lines follow, each containing m integers. The j-th integer in the i-th line is Ai,j. Each integer is either 0 or 1

.

Output

If it is impossible to make B

equal to A, print one integer −1

.

Otherwise, print any sequence of operations that transforms B

into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set Bx,y, Bx,y+1, Bx+1,y and Bx+1,y+1 to 1). The condition 0≤k≤2500

should hold.

Examples
Input

Copy
3 3
1 1 1
1 1 1
0 1 1
Output

Copy
3
1 1
1 2
2 2
Input

Copy
3 3
1 0 1
1 0 1
0 0 0
Output

Copy
-1
Input

Copy
3 2
0 0
0 0
0 0
Output

Copy
0
Note

The sequence of operations in the first example:

000000000→110110000→110110110→110111111

题意:

给两个n*m的01矩阵A和B,给出了A中的元素,B中元素全为0,现在有一个操作可以在B中选一个坐标,它和右边下面右下的元素都变为1,问能否通过一些操作(不要求最少)使得B等于A,若能则输出步数和坐标,否则输出-1

思路:

暴力并判断边界(当时忘记判断边界结果被Hack了 ~TAT~ )

 #include<bits/stdc++.h>
using namespace std;
const int amn=;
int a[amn][amn],idx[amn][amn],ansx[],ansy[];
int main(){
int n,m,tp=,valid=;
cin>>n>>m;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
cin>>a[i][j];
idx[i][j]=;
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(a[i][j]){
if(!idx[i][j]&&(i+>n||j+>m)){ ///这里判断边界条件被hack了...当时想着i<n&&j<m,判非法时忘记判边界了
valid=0;
break;
}
if(a[i][j+]&&a[i+][j]&&a[i+][j+]){
idx[i][j+]=idx[i+][j]=idx[i+][j+]=;
ansx[++tp]=i;ansy[tp]=j;
}
else if(!idx[i][j]&&(!idx[i][j+]||!idx[i+][j]||!idx[i+][j+])){
valid=;
break;
}
}
}
if(valid==)break;
}
if(valid){
cout<<tp<<endl;
for(int i=;i<=tp;i++)cout<<ansx[i]<<' '<<ansy[i]<<endl;
}
else cout<<-<<endl;
}
/**
给两个n*m的01矩阵A和B,给出了A中的元素,B中元素全为0,现在有一个操作可以在B中选一个坐标,它和右边下面右下的元素都变为1,问能否通过一些操作(不要求最少)使得B等于A,若能则输出步数和坐标,否则输出-1
暴力并判断边界
**/

[暴力] Educational Codeforces Round 71 (Rated for Div. 2) B. Square Filling (1207B)的更多相关文章

  1. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  2. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  3. Educational Codeforces Round 71 (Rated for Div. 2)

    传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...

  4. Educational Codeforces Round 71 (Rated for Div. 2) Solution

    A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...

  5. Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing

    一道容斥题 如果直接做就是找到所有出现过递减的不同排列,当时硬钢到自闭,然后在凯妹毁人不倦的教导下想到可以容斥做,就是:所有的排列设为a,只考虑第一个非递减设为b,第二个非递减设为c+两个都非递减的情 ...

  6. Educational Codeforces Round 71 (Rated for Div. 2) E XOR Guessing (二进制分组,交互)

    E. XOR Guessing time limit per test1 second memory limit per test256 megabytes inputstandard input o ...

  7. [贪心,dp] Educational Codeforces Round 71 (Rated for Div. 2) C. Gas Pipeline (1207C)

    题目:http://codeforces.com/contest/1207/problem/C   C. Gas Pipeline time limit per test 2 seconds memo ...

  8. Remainder Problem(分块) Educational Codeforces Round 71 (Rated for Div. 2)

    引用:https://blog.csdn.net/qq_41879343/article/details/100565031 下面代码写错了,注意要上面这种.查:2  800  0,下面代码就错了. ...

  9. XOR Guessing(交互题+思维)Educational Codeforces Round 71 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1207/problem/E 答案guessing(0~2^14-1) 有两次机会,内次必须输出不同的100个数,每次系统会随机挑一个你给 ...

随机推荐

  1. http客户端如何写

    使用wireshark协助,设置网卡本地,设置过滤器:http && (ip.src == 192.168.1.80 && ip.dst == 192.168.1.81 ...

  2. 微信小程序入门讲解

    微信小程序 注册 由于发文限制,请自行到微信公众平台注册 项目结构 project.config.json 配置文件(不需要动) app.json(用户配置) 路由pages window 整个程序样 ...

  3. 从头认识js-函数表达式

    定义函数的方式有两种: 1.函数声明(特征:函数声明提升,在执行代码之前会先读取函数声明,这就意味着可以把函数声明放在调用它的语句之后) 2.函数表达式(函数表达式与其他表达式一样,使用之前必须先声明 ...

  4. node跨域方法

    第一种:jsonp 参看用nodejs实现json和jsonp服务 第二种:res.wirteHeadnode部分 var http = require('http') var url = requi ...

  5. 手摸手教你在vue-cli里面使用vuex,以及vuex简介

    写在前面: 这篇文章是在vue-cli里面使用vuex的一个极简demo,附带一些vuex的简单介绍.有需要的朋友可以做一下参考,喜欢的可以点波赞,或者关注一下,希望可以帮到大家. 本文首发于我的个人 ...

  6. 前端每日实战:42# 视频演示如何用纯 CSS 创作一个均衡器 loader 动画

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/oybWBy 可交互视频教程 此视频 ...

  7. 2020年,如何成为一名 iOS 开发高手!

    2020年对应程序员来说,是一个多灾的年份,很多公司都进行了不同比例的优化和裁员.等疫情得到控制后,将会是找工作的高峰期,从去年的面试经历来看,现在只会单纯写业务代码的人找工作特别难,很多大厂的面试官 ...

  8. dom节点及对节点的常用操作方法

    dom节点及对节点的常用操作方法 在说dom节点前,先来看看页面的呈现: dom渲染流程:  1.浏览器解析html源码,然后创建一个DOM树. 在DOM树中,每一个HTML标签都有一个对应的节点(元 ...

  9. cmd 输入输出

    cmd 输入输出 首先在编写如: #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> vo ...

  10. frida报错frida.InvalidArgumentError: device not found问题解决方案

    一.问题描述     python安装好frida框架后,在安卓端启动了frida-server,启动要hook的应用,在cmd中执行python脚本,报错frida.InvalidArgumentE ...