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 ...
随机推荐
- 9、SpringBoot-CRUD国际化
1).编写国际化配置文件: 2).使用ResourceBundleMessageSource管理国际化资源文件 3).在页面使用fmt:message取出国际化内容 步骤: 1).编写国际化配置文件, ...
- sublime text 插件及快捷键的使用
安装插件准备步骤: 1.先安装管理插件,插件必备:package control 1.按ctrl+` 调出console 2.在底部代码行粘贴以下代码并回车: import urllib2,os;pf ...
- Gradle Goodness: Working with Live Task Collection
Gradle support the definition of so called live collections. These collections are mostly created ba ...
- winform 实现定位
如何在winform中 导入地图实现定位功能 ? 从网上下个BaiDuMap.htm, 就是个js文件 在form中加入webBrowser控件,然后在窗体的加载事件中写入如下代码 webBro ...
- js判断中文字符串长度和js截取中文字符串
//获取字符串长度String.prototype.strLen = function() { var len = 0; for (var i = 0; i < this.length; i++ ...
- ArrayList的去重问题
面试被问及arraylist的去重问题,现将自己想的两种解决方案写在下面 /** * Description: * ClassName:Uniq * Package:com.syd.interview ...
- 工具 | Axure基础操作 No.2
不废话了,直接如之前一样上操作图才是正道. 1.设置文本类型为密码或者文件类型 可以在属性中也选择最大长度制定长度. 如果设置类型为文件,在浏览器中就会自动变成选择本地文件的按钮. 2.文本框提示文字 ...
- weex图片加载更多方法loadmore的使用
首先,放一个weex中loadmore使用的demo,可以看一下http://dotwe.org/vue/8dd2a10c69e149ae8971f8298cc8bebf 1.在list标签上添加 @ ...
- python函数名应用
函数名的应用 函数名 的应用分类: 函数就是一个特殊的变量(可以看成一个变量来用) *函数名对应函数的内存地址 *函数名可以做为容器类数据的元素 *函数名可以作为函数的参数 *函数名可以作为函数的返回 ...
- Java 8 – Map排序
前提 Map是Java中最常用的集合类之一,这里整理了关于HashMap的排序 (关于List的排序,请查看Collections.sort()的doc或源码). 将无序的HashMap借助Strea ...