[暴力] 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个数,每次系统会随机挑一个你给 ...
随机推荐
- hexo及next主题修改
通过npm uninstall <package>命令,你可以将node_modules目录下的某个依赖包移除: 1 npm uninstall 包名 要从package.json文件的依 ...
- Activity源码解析 - 读书笔记
1. Activity启动 Activity是一个比较好的模板方法模式.在Android系统启动时,第一个启动的进程是zygote进程,然后由zygote启动SystemServer,再后就是启动AW ...
- CSS中怎么设置元素水平垂直居中?
记录怎么使用text-align与vertical-align属性设置元素在容器中垂直居中对齐.text-align与vertical-align虽然都是设置元素内部对齐方式的,但两者的用法还是有略微 ...
- 【2020Python修炼记3】初识Python,你需要知道哪些(一)
一.编程语言简介 机器语言 计算机能直接理解的就是二进制指令,所以机器语言就是直接用二进制编程,这意味着机器语言是直接操作硬件的,因此机器语言属于低级语言, 此处的低级指的是底层.贴近计算机硬件(贴近 ...
- SQL Server 最小日志记录
SQL Server之所以记录事务日志,首要目的是为了把失败或取消的操作还原到最原始的状态,但是,并不是所有的操作都需要完全记录事务日志,比如,在一个空表上放置排他锁,把大量的数据插入到该空表中.即使 ...
- 使用HBuilder开发移动APP:ajax调用接口数据
既然要做APP,与接口交互式少不了的,除非只是想做一个纯静态的APP.所以html5+的环境准备好后,我最先开始研究的就是如何与接口交互. 使用HBuilder新建示例教程后,里面会有一个ajax(网 ...
- 初窥构建之法——记2020BUAA软工个人博客作业
项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任建) 这个作业的要求在哪里 个人博客作业 我在这个课程的目标是 完成一次完整的软件开发经历并以博客的方式记录开发过程的心得掌握 ...
- python之路-基本数据类型之list列表
1.概述 列表是python的基本数据类型之一,是一个可变的数据类型,用[]方括号表示,每一项元素使用逗号隔开,可以装大量的数据 #先来看看list列表的源码写了什么,方法:按ctrl+鼠标左键点li ...
- 2019-2020-3 20174318张致豪《网络对抗技术》Exp2 后门原理与实践
Exp2 后门原理与实践 前期准备 一.实验目标与基础知识 1.1 实践目标 使用netcat获取主机操作Shell,cron启动 使用socat获取主机操作Shell,任务计划启动 使用MSF m ...
- Web实验一 国内旅游界面
Web实验一 旅游界面的设计 一.首页代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <me ...