[暴力] 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个数,每次系统会随机挑一个你给 ...
随机推荐
- 关于android应用程序的入口
android应用程序,由一到多个Activity组成.每个Activity没有很紧密的联系,因为我们可以在自己的程序中调用其它Activity,特别是调用自己的代码之外生成的Activity,比如a ...
- 【问】:和=在map里面的区别
- 滑动表层div时 禁止底层滑动
$(".container").bind("touchstart", function (events) { startX = events.originalE ...
- GIT 使用(一):安装和配置
安装和配置 Table of Contents 1. 安装 2. 配置 1. 初次运行 Git 前的配置 小结 2. 用户信息 3. 别名 4. 查看已经存在的配置 3. 获取帮助 4. 参考与扩展阅 ...
- flask 参数校验
校验参数是否存在,不存在返回400 @app.route('/check',methods=['POST']) def check(): values = request.get_json() req ...
- 利用canvas绘画二级树形结构图
上周需要做一个把页面左侧列表内容拖拽到右侧区域,并且绘制成关系树的功能.看了设计图,第一反应是用canvas绘制关系线.吭哧吭哧搞定这个功能后,发现用canvas绘图,有一个很严重的缺陷.那就是如果左 ...
- mysql 常用获取时间sql语句
--当年第一天: SELECT DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY); --当年最后一天: SELECT concat(YEAR(no ...
- 阿里云上docker部署nginx实现反向代理
简介 需要从镜像仓库找到所需要的nginx版本pull下来.(地址:https://hub.docker.com/) 1.docker pull nginx 1.挂载目录 1.1 获取nginx. ...
- localStorage,sessionStorage的方法重写
本文是针对于localStorage,sessionStorage对于object,string,number,bollean类型的存取方法 我们知道,在布尔类型的值localStorage保存到本地 ...
- AI广度优先搜索算法,项目实战北京地图/贪心学院
广度优先搜索算法详解地铁路线 北京很大,附上地铁图,不要迷路!!! 作为一个程序员,在北京,你很有可能住在回龙观地区,经常从龙泽上地铁,然后畅游北京. 当有一天,你老家的朋友来北京了,希望你能够带她去 ...