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
  1. 3 3
  2. 1 1 1
  3. 1 1 1
  4. 0 1 1
Output

Copy
  1. 3
  2. 1 1
  3. 1 2
  4. 2 2
Input

Copy
  1. 3 3
  2. 1 0 1
  3. 1 0 1
  4. 0 0 0
Output

Copy
  1. -1
Input

Copy
  1. 3 2
  2. 0 0
  3. 0 0
  4. 0 0
Output

Copy
  1. 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~ )

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int amn=;
  4. int a[amn][amn],idx[amn][amn],ansx[],ansy[];
  5. int main(){
  6. int n,m,tp=,valid=;
  7. cin>>n>>m;
  8. for(int i=;i<=n;i++){
  9. for(int j=;j<=m;j++){
  10. cin>>a[i][j];
  11. idx[i][j]=;
  12. }
  13. }
  14. for(int i=;i<=n;i++){
  15. for(int j=;j<=m;j++){
  16. if(a[i][j]){
  17. if(!idx[i][j]&&(i+>n||j+>m)){ ///这里判断边界条件被hack了...当时想着i<n&&j<m,判非法时忘记判边界了
  18. valid=0;
  19. break;
  20. }
  21. if(a[i][j+]&&a[i+][j]&&a[i+][j+]){
  22. idx[i][j+]=idx[i+][j]=idx[i+][j+]=;
  23. ansx[++tp]=i;ansy[tp]=j;
  24. }
  25. else if(!idx[i][j]&&(!idx[i][j+]||!idx[i+][j]||!idx[i+][j+])){
  26. valid=;
  27. break;
  28. }
  29. }
  30. }
  31. if(valid==)break;
  32. }
  33. if(valid){
  34. cout<<tp<<endl;
  35. for(int i=;i<=tp;i++)cout<<ansx[i]<<' '<<ansy[i]<<endl;
  36. }
  37. else cout<<-<<endl;
  38. }
  39. /**
  40. 给两个n*m的01矩阵A和B,给出了A中的元素,B中元素全为0,现在有一个操作可以在B中选一个坐标,它和右边下面右下的元素都变为1,问能否通过一些操作(不要求最少)使得B等于A,若能则输出步数和坐标,否则输出-1
  41. 暴力并判断边界
  42. **/

[暴力] 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. 码海拾遗:简单Socket(TCP)类实现

    最近刚开始啃Unix网络编程(卷1:套接字联网API),为加深TCP连接的建立和终止的理解与记忆,记下本文,方便以后翻看. 同时留下的还有简单的Socket(TCP)类: mySocket.h #pr ...

  2. Excel技巧:如何绘制一份优秀的甘特图(项目管理)

    作者:秦路,天善智能特约专家.资深数据分析师,数据化运营专家.擅长结合运营和数据,建立数据化运营体系. 个人公众号:秦路(微信ID:tracykanc) 今天我给大家分享的内容是如何利用Excel绘制 ...

  3. 算法小练#1 - Dany Yang

    开始记录每周做过的算法题,这是第一周,新的开始 1021. 删除最外层的括号 题目要求如下: 有效括号字符串为空 ("")."(" + A + ")& ...

  4. 树的三种DFS策略(前序、中序、后序)遍历

    之前刷leetcode的时候,知道求排列组合都需要深度优先搜索(DFS), 那么前序.中序.后序遍历是什么鬼,一直傻傻的分不清楚.直到后来才知道,原来它们只是DFS的三种不同策略. N = Node( ...

  5. jquery.qrcode笔记

    由于一个坑爹的项目需要生成二维码扫描,后台由于数据库比较麻烦,就只能前端做了,于是乎找到Js生成qrcode的一个库:https://github.com/jeromeetienne/jquery-q ...

  6. 7-43 jmu-python-字符串异常处理 (20 分)

    输入一行字符串及下标,能取出相应字符.程序能对不合法数据做相应异常处理. 输入格式: 行1:输入一字符串 行2:输入字符下标 输出格式: 下标非数值异常,输出下标要整数 下标越界,输出下标越界 数据正 ...

  7. vs2019 目标框架是灰色的原因

    原因一是没有安装.net core 包: 如果是桌面程序,不是web程序:不安装.net core包的情况,修改工程文件 TargetFrameworks  ---->  TargetFrame ...

  8. Asp.Net Core IdentityServer4 中的基本概念

    一.前言 这篇文章可能大家会觉得很空洞,没有实际的实战东西,主要是自己整理出来的IdentityServer4 的一些概念性的东西:如果你对IdentityServer4有过一定的实战经验,可以跳过不 ...

  9. 点云3d检测模型pointpillar

    PointPillars 一个来自工业界的模型.https://arxiv.org/abs/1812.05784 3D目标检测通常做法 3d卷积 投影到前平面 在bird-view上操作 处理思路依然 ...

  10. java线程间的共享

    本次内容主要讲synchronized.volatile和ThreadLocal. 1.synchronized内置锁 线程开始运行,拥有自己的栈空间,就如同一个脚本一样,按照既定的代码一步一步地执行 ...