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(暴力)的更多相关文章

  1. B. Lost Number【CF交互题 暴力】

    B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...

  2. 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 ...

  3. [ 9.11 ]CF每日一题系列—— 441C暴力模拟

    Description: n * m 的地图,建设k个管道管道只能横竖走,且长度大于等于2,问你任意一种建设方法 Solution: 图里没有障碍,所以先把前k - 1个管道每个分2个长度,最后一个管 ...

  4. CF 987C Three displays DP或暴力 第十一题

    Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. CF 702B Powers of Two(暴力)

    题目链接: 传送门 Devu and Partitioning of the Array time limit per test:3 second     memory limit per test: ...

  6. CF 489C 暴力处理

    题意: 给你 数的长度 m, 数的每个数的和 Sum: 输出 这个数最小值 和最大值 #include<bits/stdc++.h> using namespace std; int ma ...

  7. [ 9.12 ]CF每日一题系列—— 960B暴力数组

    Description: 给你两个数组,顺序一定,问你第一个数组连续的几个值等于下一个数组连续的几个值,然后寻找这个值得最大值,也就是满足就换 Solution: 用两个变量索引,判断即可 #incl ...

  8. CF 558 C. Amr and Chemistry 暴力+二进制

    链接:http://codeforces.com/problemset/problem/558/C C. Amr and Chemistry time limit per test 1 second ...

  9. CF 305A——Strange Addition——————【暴力加技巧】

    A. Strange Addition time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. tp5.0和tp3.2中前台模板IF标签和FOREACH的区别

    IF标签 tp3.2 <if condition="($name eq 1) OR ($name gt 100) "> value1 <elseif condit ...

  2. mac git 命令自动补全

    步骤如下: 1.下载Git-completion.bash 或者直接使用SourceTree去clone到本地. 下载地址:https://github.com/markgandolfo/git-ba ...

  3. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室 实战系列(内容已过期,阅读请慎重)

    项目简介 利用ASP.NET SignalR技术与Layim前端im框架实现的一个简单的web聊天室,包括单聊,群聊,加好友,加群,好友搜索,管理,群组管理,好友权限设置等功能.涉及技术: Elast ...

  4. WEB测试—功能测试

    1. 链接测试        1.1 测试点: 是否添加链接 链接页面是否存在 链接页面与需求是否一致:页面的正确性.打开方式 等              一般,该链接测试在集成测试阶段(页面均开发 ...

  5. div拖动

    <!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head> <meta ...

  6. Paxos一致性算法(三)

    一.概述: Google Chubby的作者说过这个世界只有一种一致性算法,那就Paxos算法,其他的都是残次品. 二.Paxos算法: 一种基于消息传递的高度容错性的一致性算法. Paxos:少数服 ...

  7. oracle sqldrl命令与以及ctl文件

    具体操作如下: 第一步:先编辑好数据控制文件 xx.ctl,如test.ctl options(skip=1)   --跳过第一行(看实际情况) load data infile 'C:\Users\ ...

  8. 原生js实现简单的随机点名系统

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  9. java并发实战:连接池实现

    池化技术简介 在我们使用数据库的过程中,我们往往使用数据库连接池而不是直接使用数据库连接进行操作,这是因为每一个数据库连接的创建和销毁的代价是昂贵的,而池化技术则预先创建了资源,这些资源是可复用的,这 ...

  10. JavaScript 中 Property 和 Attribute 的区别详解

    property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...