CF508A Pasha and Pixels 题解
Content
有一个 \(n\times m\) 的矩阵,一开始全部格子被染成白色。 接下来有 \(k\) 个操作,每一个操作表示把一个格子染成黑色。问第一次出现 \(2\times 2\) 的全部涂成黑色的矩阵是第几个操作,或者没有出现这样的矩阵。
数据范围:\(1\leqslant n,m\leqslant 1000,1\leqslant k\leqslant 10^5\)。
Solution
我们可以边涂黑边判断,假设现在将 \((x,y)\) 涂成黑色。那么,出现一个 \(2\times 2\) 的全部涂成黑色的矩阵只会有 \(4\) 种情况:
- \((x,y),(x-1,y),(x,y-1),(x-1,y-1)\) 全部涂成黑色。
- \((x,y),(x+1,y),(x,y-1),(x+1,y-1)\) 全部涂成黑色。
- \((x,y),(x-1,y),(x,y+1),(x-1,y+1)\) 全部涂成黑色。
- \((x,y),(x+1,y),(x,y+1),(x+1,y+1)\) 全部涂成黑色。
只要满足上面四种情况中的任意一种,直接输出答案结束。否则,操作全部执行完毕还是没有出现,输出 \(0\)。
Code
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int n, m, k, a[1007][1007];
bool check1(int x, int y) {
return a[x][y] && a[x - 1][y] && a[x][y - 1] && a[x - 1][y - 1];
}
bool check2(int x, int y) {
return a[x][y] && a[x + 1][y] && a[x][y - 1] && a[x + 1][y - 1];
}
bool check3(int x, int y) {
return a[x][y] && a[x - 1][y] && a[x][y + 1] && a[x - 1][y + 1];
}
bool check4(int x, int y) {
return a[x][y] && a[x + 1][y] && a[x][y + 1] && a[x + 1][y + 1];
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= k; ++i) {
int x, y;
scanf("%d%d", &x, &y);
a[x][y] = 1;
if(check1(x, y) || check2(x, y) || check3(x, y) || check4(x, y))
return printf("%d", i), 0;
}
return printf("0"), 0;
}
CF508A Pasha and Pixels 题解的更多相关文章
- 【codeforces 508A】Pasha and Pixels
[题目链接]:http://codeforces.com/contest/508/problem/A [题意] 让你在一个n*m的方格上给方格染色; 顺序给出染色的k个格子 如果在某一时刻 有一个2* ...
- 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...
- Codeforces Round #288 (Div. 2)
A. Pasha and Pixels 题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: ...
- UVA - 297Quadtrees(四分图)
Quadtrees Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Statu ...
- LeetCode Smallest Rectangle Enclosing Black Pixels
原题链接在这里:https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/ 题目: An image is rep ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 水题
A. Pasha and Stick Pasha has a wooden stick of some positive integer length n. He wants to perform ...
- 302. Smallest Rectangle Enclosing Black Pixels
题目: An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The b ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...
- Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题
B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...
随机推荐
- springboot静态工具类bean的注入
工具类中调用数据.但是由于工具类方法一般都写成static,所以直接注入就存在问题. 所以写成了这样: package com.rm.framework.core; import org.spring ...
- Codeforces 1368E - Ski Accidents(构造+思维)
Codeforces 题面传送门 & 洛谷题面传送门 神仙构造题(不过可能我构造太烂了?) 首先考虑这个奇奇怪怪的 \(\dfrac{4}{7}\),以及这个每个点出度最多为 \(2\) 的条 ...
- 【豆科基因组】大豆(Soybean, Glycine max)经典文章梳理2010-2020
目录 2010年1月:大豆基因组首次发表(Nature) 2010年12月:31个大豆基因组重测序(Nature Genetics) 2014年10月:野生大豆泛基因组(Nature Biotechn ...
- SNPEFF snp注释 (添加自己基因组)
之间介绍过annovar进行对snp注释,今天介绍snpEFF SnpEff is a variant annotation and effect prediction tool. It annota ...
- W10: Warning: Changing a readonly file使用vi/vim报错问题解决
使用vi/vim编辑文件的时候出现W10: Warning: Changing a readonly file报错 解决方法: 一.强制保存退出 :wq! 二.ll 查询文件属主,使用属主赋予权限 c ...
- Linux—su命令和su -命令的差别(切换登录账号)
1.普通用户切换到root用户,命令su或su - 本人以前一直习惯直接使用root,很少使用su,前几天才发现su与su -命令是有着本质区别的! 大部分Linux发行版的默认账户是普通用户,而更改 ...
- words in English that contradict themselves
[S1E10, TBBT]Leonard: I don't get it. I already told her a lie. Why would I replace it with a differ ...
- 基于MQTT协议实现远程控制的"智能"车
智能,但不完全智能 虽然我不觉得这玩意儿有啥智能的,但都这么叫就跟着叫喽. 时隔好几天才写的 其实在写这篇博文的时候我已经在做升级了,并且已经到了中后期阶段了. 主要是业余时间做着玩,看时间了. 规格 ...
- Azkaban(二)【WorkFlow案例实操】
目录 1.使用步骤 2.案例: 1.hello word 2.作业依赖[dependsOn配置作业的依赖关系] 3.内嵌工作流 4.全局配置 [在开头通过config进行配置,后续可以通过${属性名} ...
- cookie规范(RFC6265)翻译
来源:https://github.com/renaesop/blog/issues/4 RFC 6265 要点翻译 1.简介 本文档定义了HTTP Cookie以及HTTP头的Set-Cookie字 ...