CF1207B
CF1207B-Square Filling
题意:
两个矩阵a,b,已知矩阵b,每次能修改b矩阵中相邻的四个格(b为空矩阵),使b变为a
解法:
枚举矩阵中的1,按题意修改,并把改过的四个点都标记一下。
注意每次枚举的点一定是未被标记过的,不然连pretest都过不去。
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
#define N 60
int a[N][N],b[N][N],m,n;
int main() {
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
scanf("%d",&a[i][j]);
}
}
int ans = 0;
for(int i = 1; i < n; i++) {
for(int j = 1; j < m; j++) {
if(a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1] == 4) {
b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = 1;
ans++;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] ^ b[i][j]) {
puts("-1");
return 0;
}
}
}
printf("%d \n",ans);
for(int i = 1; i < n; i++) {
for(int j = 1; j < m; j++) {
if(a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1] == 4) {
printf("%d %d \n",i,j);
}
}
}
//system("pause");
return 0;
}
CF1207B的更多相关文章
随机推荐
- T4模板生成文件要点记录
可以使用 $(variableName) 语法引用 Visual Studio 或 MSBuild 变量(如 $(SolutionDir)),以及使用 %VariableName% 来引用环境变量.介 ...
- JS基础_实参可以是任何值
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- luogu4777[模板]拓展中国剩余定理题解
题目链接 https://www.luogu.org/problemnew/show/P4777 分析 扩展\(CRT\)就是解决模数不互质的情况,说是扩展\(CRT\),其实都是扩欧... 先来考虑 ...
- css优先级及其对应的权重
1.选择器的优先级 !important>内联选择器(style)>id选择器>类选择器 | 属性选择器 | 伪类选择器 > 元素选择器>通配符(*) 2.选择器的权重( ...
- 小程序page中生命周期
onLoad -- 页面被加载出来 onShow -- 页面显示出来后 退出后两小时进来,只会执行这个生命周期 onRady -- (逻辑层传给渲染层后才会执行)监听页面初次渲染完成 onHide ...
- SpringBoot--多环境部署配置文件
在resources 下创建 application-{profile}.properties 的配置文件,其中profile是任意名字: test:测试环境 prod:线上环境 pre-prod:预 ...
- C# 校验车架号(VIN码)第9位是否有效算法
public static bool checkVIN(string vin) { //VIN码从第1位到第17位的“加权值”: Dictionary<int, int> vinMapWe ...
- PropertiesUtils(普遍做法)
public class PropertiesUtil{ private static Properties properties; static{ InputStream in = null; tr ...
- ssh-copy-id三步实现SSH无密码登录和ssh常用命令
第一步:在本地机器上使用ssh-keygen产生公钥私钥对 $ ssh-keygen 第二步:用ssh-copy-id将公钥复制到远程机器中 $ ssh-copy-id -i .ssh/id_rsa ...
- Flutter——Padding组件
在 html 中常见的布局标签都有 padding 属性,但是 Flutter 中很多 Widget 是没有 padding 属性.这个时候我们可以用 Padding 组件处理容器与子元素直接的间距. ...