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. 14、SpringBoot-CRUD错误处理机制(1)

    一.springboot默认的处理机制 1.浏览器返回一个错误的页面 默认处理错误:返回一个错误的页面: 包括错误类型.时间......   2.其他客户端访问 默认响应一个json数据 原理: 错误 ...

  2. 【VS插件】Highlight all occurrences of selected word

    这个插件可以让相同的单词全部高亮成绿色,在VS中看一些文本(比如SQL)类型的文件时非常好用. 类似于这种效果:

  3. ESP8266 wifi干扰钓鱼实现

    说明:绝大部分都是对着下面的参考文章来做的.这里只把基本流程和我自己遇到的问题写一下.如有其他问题可以访问文章末的参考文章进行查找! esp8266模块 我们需要购买一块esp8266模块,如下图所示 ...

  4. lead over 和 lag over

    今天在熟悉项目的某个功能模块时,查看mybatis的映射文件内发现这样的一串sql: (T.NET_VALUE - LEAD(T.NET_VALUE)OVER(ORDER BY T.ESTIMATE_ ...

  5. 【usaco】1.1

    你的飞碟在这儿Your Ride Is Here(难度:入门难度) 题目链接 题目大意 emmmm 输入两个字符串,问他们每个字母的asco码相乘后字符串是否相等. 思路 一道水题?(雾) 错误代码: ...

  6. Centos配置静态IP

    ifconfig -a           //看IP,HWADDR netstat   -rn       //看网关 service network restart  //重启网卡 输入命令:vi ...

  7. datatable去掉表头默认排序

    禁用排序:"ordering":false 某一列禁用排序:"orderable":false 以某一列排序:"order":[[x,&qu ...

  8. Java 创建线程的方式

    想必大家在Java面试中经常会被问到有关线程的问题,最常见的莫过于“Java有哪几种创建线程的方式呢?” 稍稍了解过,或者在日常开发中也都会用到以下几种方式: ①继承Thread类(真正意义上的线程类 ...

  9. angular常用属性大全

    Angular元素属性大全 addClass()-为每个匹配的元素添加指定的样式类名 after()-在匹配元素集合中的每个元素后面插入参数所指定的内容,作为其兄弟节点 append()-在每个匹配元 ...

  10. tcp总结与简单实现

    一.TCP简介 1. TCP介绍 1)TCP协议,传输控制协议(Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议 2)t ...