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. 解决appium升级后不支持使用name定位的问题

    前言 之前一直用的appium1.4版本,最近升级到了1.6突然发现之前的脚本好多都跑失败了,一看报错: selenium.common.exceptions.InvalidSelectorExcep ...

  2. 产品需求说明书PRD模版

    <软件自动化测试开发>出版了 XXX产品需求说明书 [版本号:V+数字]                 编  制: 日  期: 评  审: 日  期: 批  准: 日  期:       ...

  3. GeoMesa-单机搭建

    系统安装 CentOS部署 新建虚拟电脑 类型:Linux 版本:Red Hat(64-bit) 创建虚拟硬盘 [x] 动态分配(磁盘占用较小) [ ] 固定大小(使用起来较快) 安装设置(设置roo ...

  4. AngularJS入门篇

    AngularJS是一个JavaScript框架,它通过指令扩展了HTML,且通过表达式绑定数据到 HTML.顺便一提,什么是框架?比如struts2.spring.hibernate.thinkph ...

  5. c#或者C#.net中的“ToolTip”是“System.Windows.Forms.ToolTip”和“DevComponents.DotNetBar.ToolTip”之间的不明确的引用

    “ToolTip”是“System.Windows.Forms.ToolTip”和“DevComponents.DotNetBar.ToolTip”之间的不明确的引用 ,在编程时,有时候会编译出现不明 ...

  6. string类中getline函数的应用

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  7. 10分钟进阶SpringBoot - 05. 数据访问之JDBC(附加源码分析+代码下载)

    10分钟进阶SpringBoot - 05. 数据访问之JDBC 代码下载:https://github.com/Jackson0714/study-spring-boot.git 一.JDBC是什么 ...

  8. .Net Core中使用ExceptionFilter

    .Net Core中有各种Filter,分别是AuthorizationFilter.ResourceFilter.ExceptionFilter.ActionFilter.ResultFilter. ...

  9. pycharm在windows中如何安装dlib?

    pycharm在windows下安装dlib库的时候,出现以下错误(等等类似的问题): 解决办法: 1.这个方法无关紧要,只是记录一下:将清华源替换为阿里源: C:\Users\Administrat ...

  10. linux构建DHCP服务器

    1.DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议,使用UDP协议工作,主要用途:给内部网络或网络服务供应商自动分配IP地址 ...