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 ...
随机推荐
- log4net快速使用流程
以下内容大部分来自这里,对原作者流子表示感谢 1.Nuget安装,当前版本2.0.8 2.创建log4net.config文件,文件内容如下: <?xml version="1.0&q ...
- swagger ui和spring boot集成生成api文档
作者:小莫链接:https://www.zhihu.com/question/28119576/answer/134580038来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- tomcat快速部署War包操作
Linux快速部署War包操作,暂时是最简单的操作 1.先关闭Tomcat /home/java/tomcat7/bin/shutdown.sh 2.进入War包存放目录(可以通过工具:SSH Sec ...
- 使用document对象操作cookie
1. 使用document对象的cookie属性,可以让你读取.添加和更新文档(当期HTML)所关联的cookie. 2. 当你读取document.cookie时,会得到当期文档的所有cookie. ...
- Tuple和 ValueTuple
这个类型还是学习C#7.0的语法在看到的,这边单独拿来学习下. 学习地址: https://docs.microsoft.com/zh-cn/dotnet/csharp/tuples https:// ...
- iOS安装CocoaPods详细过程
iOS安装CocoaPods详细过程 一.简介 什么是CocoaPods CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为“Pods”的 ...
- Mac连接Linux服务器
1.终端命令 a).打开Mac的命令终端 b).输入ssh -p 22 root@101.200.86.233 它会提示你输入密码,输入正确的密码之后,你就发现已经登陆成功了.(22: 端口号 roo ...
- Ansible实现主备模式的高可用(Keepalived)
前言 Ansible是一款极其简单的IT自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序 ...
- 基于Bootstrap Ace模板+bootstrap.addtabs.js的菜单
这几天研究了基于bootstrap Ace模板+bootstra.addtabs.js实现菜单的效果 参考了这个人的博客 https://www.cnblogs.com/landeanfen/p/76 ...
- js实现所有异步请求全部加载完毕后,loading效果消失
在实际开发中,一定有情况是这样的,一个页面我们有多个地方请求了ajax,在这种情况下,我们要实现数据没来之前出现我们炫酷的loading效果,而且要等到所有的ajax都请求完毕后,才让我们的loadi ...