[暴力] Educational Codeforces Round 71 (Rated for Div. 2) B. Square Filling (1207B)
1 second
256 megabytes
standard input
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.
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
.
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.
3 3
1 1 1
1 1 1
0 1 1
3
1 1
1 2
2 2
3 3
1 0 1
1 0 1
0 0 0
-1
3 2
0 0
0 0
0 0
0
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)的更多相关文章
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- Educational Codeforces Round 71 (Rated for Div. 2)
传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...
- Educational Codeforces Round 71 (Rated for Div. 2) Solution
A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...
- Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
一道容斥题 如果直接做就是找到所有出现过递减的不同排列,当时硬钢到自闭,然后在凯妹毁人不倦的教导下想到可以容斥做,就是:所有的排列设为a,只考虑第一个非递减设为b,第二个非递减设为c+两个都非递减的情 ...
- 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 ...
- [贪心,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 ...
- Remainder Problem(分块) Educational Codeforces Round 71 (Rated for Div. 2)
引用:https://blog.csdn.net/qq_41879343/article/details/100565031 下面代码写错了,注意要上面这种.查:2 800 0,下面代码就错了. ...
- XOR Guessing(交互题+思维)Educational Codeforces Round 71 (Rated for Div. 2)
题意:https://codeforc.es/contest/1207/problem/E 答案guessing(0~2^14-1) 有两次机会,内次必须输出不同的100个数,每次系统会随机挑一个你给 ...
随机推荐
- LeetCode 题解 | 1. 两数之和
题目描述: 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], t ...
- win10安装LoadRunner时,安装.net framwork组件报0x800F081F错误 解决办法
一.报错原因 0x800F081F错误大多数是在安装软件时,系统无法联网自动下载安装. 经过各种排查及搜索解决方案,总结原因无非以下三种: 1.windows update被禁用. 2.电脑没有.ne ...
- 读书笔记-《Mysql技术内幕》
MYSQL 技术内幕 Mysql体系 连接池组件 管理服务和工具 SQL接口 查询分析器 优化器 缓冲 插件式存储引擎 物理文件 存储引擎 InnoDB(默认引擎) 支持事务 行锁设计 多版本并发控制 ...
- 2019年后,Java岗面试快速突击指南
大家好.这篇文章给大家分享一下如何获得一个可以去参加面试的最小可行知识(Minimal Viable Knowledge)!我自己在就基本上靠文章中的策略在找实习的时候拿到了头条阿里的offer.所以 ...
- ubuntu下安装typescript
安装ts之前需要安装好node, 安装ts: 1. npm install -g typescript /opt/node/bin/tsc -> /opt/node/lib/node_modul ...
- nowcoder 135F 圆
链接:https://www.nowcoder.com/acm/contest/135/F来源:牛客网 圆(circle) 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 3276 ...
- 汇编语言-[bx]和loop指令和多个段
5.1 [BX]和内存单元的描述 要完成描述一个内存单元,需要两种信息: 内存单元的地址: 可以用 [0] 表示一个内存单元, 0 表示单元的偏移地址,段地址默认在 ds 中: 同样也可以用 [bx] ...
- javascript的装饰者模式Decorator
刚开始看这段代码有点绕,现在回过头来看,so easy! Function.prototype.before = function(beforefn){ var _self = this; retur ...
- 05 mapreduce快速入门
统计HDFS的/wordcount/input/a.txt文件中的每个单词出现的次数——wordcount package cn.oracle.core; import java.io.IOExcep ...
- [JS]使用JavaScript实现简易俄罗斯方块
[JS]使用JavaScript实现简易俄罗斯方块 首先,大家可以点击此处来预览一下游戏效果,随后将会以此为模板讲解如何使用JavaScript实现这样一个简易的俄罗斯方块项目(以下简称"该 ...