cf#514B. Forgery(暴力)
B. Forgery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?
For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3square without its central cell if it is completely contained inside the grid, as shown below.
xxx
x.x
xxx
Determine whether is it possible to forge the signature on an empty n×mn×m grid.
Input
The first line of input contains two integers nn and mm (3≤n,m≤10003≤n,m≤1000).
Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.
Output
If Andrey can forge the signature, output "YES". Otherwise output "NO".
You can print each letter in any case (upper or lower).
Examples
input
Copy
3 3
###
#.#
###
output
Copy
YES
input
Copy
3 3
###
###
###
output
Copy
NO
input
Copy
4 3
###
###
###
###
output
Copy
YES
input
Copy
5 7
.......
.#####.
.#.#.#.
.#####.
.......
output
Copy
YES
Note
In the first sample Andrey can paint the border of the square with the center in (2,2)(2,2).
In the second sample the signature is impossible to forge.
In the third sample Andrey can paint the borders of the squares with the centers in (2,2)(2,2) and (3,2)(3,2):
we have a clear paper:
...
...
...
...
use the pen with center at (2,2)(2,2).
###
#.#
###
...
use the pen with center at (3,2)(3,2).
###
###
###
###
In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3)(3,3) and (3,5)(3,5).
题意:模仿老师的签名,每次写下去都是3*3的矩阵,中间没有墨,给出一个矩阵表示老师的签名,问能不能模仿成功
题解:暴力,输入的时候计算#的个数sum,最外面一圈是不用看的,从第二行第二列开始,假设该位置是3*3矩阵的中间,看该点周围一圈是不是都是#或者已经写过的#,如果是就算写一次,并计算该次覆盖的#个数(之前没有覆盖过的)cnt,并标记已经覆盖过的。最后比较cnt是不是等于sum,如果等于就表示可以模仿成功。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char c[][];
int b[][]={{-,-},{-,},{-,},{,-},{,},{,-},{,},{,}};
int main(){
int n,m,i,j,o;
while(cin>>n>>m){
int sum=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
cin>>c[i][j];
if(c[i][j]=='#') sum++;
}
int cnt=;
for(i=;i<=n-;i++)
{
for(j=;j<=m-;j++)
{
int md=;
for(o=;o<;o++){//遍历周围8个方向,看是否是可以画的,1表示之前已经画过的,但还是可以画的
if(c[ i+ b[o][] ][ j+b[o][] ]=='#'||c[ i+ b[o][] ][ j+b[o][] ]=='')
md++;
else continue;
}
if(md==) {
for(o=;o<;o++){
if(c[ i+ b[o][] ][ j+b[o][] ]=='#')//为了不重复计数,只有表示#的可以计数
cnt++; //表示已经画过的#,如果最后和sum(总的#数)相等,就表示可以画,输出yes
c[ i+ b[o][] ][ j+b[o][] ]='';
}
}
}
}
if(cnt==sum) cout<<"YES\n";
else cout<<"NO\n";
}
return ;
}
cf#514B. Forgery(暴力)的更多相关文章
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
- CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- [ 9.11 ]CF每日一题系列—— 441C暴力模拟
Description: n * m 的地图,建设k个管道管道只能横竖走,且长度大于等于2,问你任意一种建设方法 Solution: 图里没有障碍,所以先把前k - 1个管道每个分2个长度,最后一个管 ...
- CF 987C Three displays DP或暴力 第十一题
Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 702B Powers of Two(暴力)
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:3 second memory limit per test: ...
- CF 489C 暴力处理
题意: 给你 数的长度 m, 数的每个数的和 Sum: 输出 这个数最小值 和最大值 #include<bits/stdc++.h> using namespace std; int ma ...
- [ 9.12 ]CF每日一题系列—— 960B暴力数组
Description: 给你两个数组,顺序一定,问你第一个数组连续的几个值等于下一个数组连续的几个值,然后寻找这个值得最大值,也就是满足就换 Solution: 用两个变量索引,判断即可 #incl ...
- CF 558 C. Amr and Chemistry 暴力+二进制
链接:http://codeforces.com/problemset/problem/558/C C. Amr and Chemistry time limit per test 1 second ...
- CF 305A——Strange Addition——————【暴力加技巧】
A. Strange Addition time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 浅谈DB2的四个隔离级别
隔离级别定义用于控制并发事务的行为,它决定在访问数据时数据是如何锁定的.如何与其他进程隔离的. 包括四个级别,级别从高到低: RR(可重复读取) RS(读取稳定性) CS(游标稳定性) UR(未提交的 ...
- YUV display in OpenGL
http://stackoverflow.com/questions/1106741/need-help-with-yuv-display-in-opengl I am having trouble ...
- iOS视频处理
在iOS中,apple提供了AVFoundation 用来处理音视频,基本能满足一些常用的音视频处理需求,而且能调用的硬件编解码接口,能提高不少效率,这是其它库所不能达到的.最近做过的Recnow S ...
- iOS开发神器InjectionIII
最近发现了一款适用于iOS开发的神器,希望可以和大家一起分享,同时自己也将有用的东西记录下来,没错就是InjectionIII! 先看一下使用流程: 1.在MAC的App Store里面搜索下载这个工 ...
- ABI是什么? Swift ABI稳定有什么好处?
ABI是什么? 在软件开发中, 应用程序机器二元码界面(Application Binary Interface 简称ABI)指两个程序模块间的接口; 通常其中一个车还给你徐模块会是库或者操作系统提供 ...
- 在mac下运行 npm run eject 出现报错问题解决方法
当使用create-react-app创建项目后,接着运行npm run eject时,如果出现下面的错误 可能是脚手架添加了.gitignore这个文件,但是没有本地仓库,可以使用以下代码解决这个问 ...
- [videos系列]日本的videos视频让男人产生了哪些误解?
转载自:[videos系列]日本的videos视频让男人产生了哪些误解? 日本的videos视频是每个男人成长过程中都会看的启蒙教育片,也是男人在成年后调剂生活的必需品,但是由于影视作品是艺术的,是属 ...
- Handshake Lemma
- finite undirected gragh ∑deg(v) = 2|E| In a k-ary tree where every node has either 0 or k children ...
- npm常见配置收集
npm代理设置为走ss通道:npm config set proxy 'http://localhost:1080'
- 07.安装及使用gitlub
博客为日常工作学习积累总结: 1.安装gitlub sudo yum install -y curl policycoreutils-python openssh-server openssh-cli ...