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 ...
随机推荐
- Swift-技巧(八)CVPixelBuffer To CGImage
摘要 Swift 中图像的表现形式不只是 Image,还有更加底层的方式,比如 CVPixelBuffer 像素缓存形式,那么像素缓存转换为可以在应用中展示的 CGImage,就要知道有哪些处理了. ...
- vue局部过滤器和全局过滤器
全局过滤器在main.js中写 //注册全局过滤器 Vue.filter('wholeMoneyFormat',(value)=>{ return '¥'+Number(value).toF ...
- 7.3 自定义镜像-运行nginx与tomcat并结合PV/PVC/NFS以实现动静分离示例
1.在NFS SERVER上为tomcat.nginx创建相关目录 NFS SERVER的部署配置参考:https://www.cnblogs.com/yanql/p/15410308.html 1. ...
- c# Quartzs定时器的简单使用
使用背景: 首先想到倒计时,定时任务.大家想到的肯定就是定时器.那么定时器在web和winfrom程序中有着很大的作用.那在服务器端有没有像定时器一样的存在呢. 有了这些需求,我找到了第三方的组件 Q ...
- C++匿名函数的使用
c++匿名函数使用方法 1.匿名函数的使用 匿名函数的基本语法为: //[捕获列表](参数列表)->返回类型{函数体} int main() { auto Add = [](int a, int ...
- Perl语言入门14-17
---------第十四章 字符串与排序------------------- index查找子字符串 my $stuff = "howdy world!"; my $where ...
- NECAT组装ONT long reads
NECAT 可用于ONT数据的纠错,组装,如果想对ONT long reads进行call SV,也可以使用necatsv. githup网址:https://github.com/xiaochuan ...
- mysql-select as
给查询对象起个别名. 把查询对像起个别名的作用. select ID as 用户ID,Name as 用户名 from Table_user
- Linux服务器I/O性能分析-3
一.通过脚本分析IO的读/写数量.最大延迟.延迟的分布情况.块大小及数量 #!/bin/sh # # File Name : count_io.sh # Time : 2020-07-29-11:24 ...
- kubernetes部署kube-controller-manager服务
本文档介绍部署高可用 kube-controller-manager 集群的步骤. 该集群包含 3 个节点,启动后将通过竞争选举机制产生一个 leader 节点,其它节点为阻塞状态.当 leader ...