Forgery CodeForces - 1059B
一道印章刻印的题目;
具体要求:有一个固定的3*3的印章,给你一个墨迹问能用这个印章印出墨迹吗?(一个像素可以多次被上色)
输入:第一行是墨迹的行列规模,接下来是墨迹
输出:If Andrey can forge the signature, output "YES". Otherwise output "NO".
印章长这样 : 
1. 规模不算特别大,保险起见我用的是scanf读入数据,最后AC后测试发现TIME影响不大。(毕竟思路比较耗时,还是喜欢scanf)
2.思路分析:怎样的'#'才是可以被印上的,这是个关键;
3.细节实现:对所有的印章位置预先遍历一下,这里(ok函数里)要判断你传入函数的一个印章是可以被印的吗?如果在周围的8个位置上出现了'.',那么这是一个非法的位置,直接结束;
如果这是合法的位置用数组v的index来记录周围8个位置(bool值为1)
最后在遍历匹配一下就OK了。
#include<cstdio>
using namespace std;
const int max_size = + ;
char s[max_size][max_size];
bool v[max_size][max_size];
int n, m;//m行n列
bool ok(int x,int y)
{
for(int i=x;i<=x+;i++)
for (int j = y; j <= y + ; j++)
{
if (i == x + && j == y + )continue;
else if (s[i][j] == '.') return false;
}
for (int i = x; i <= x + ; i++)
for (int j = y; j <= y + ; j++)
{
if (i == x + && j == y + )continue;
else v[i][j] = ;
}
return true;
}
int main()
{
memset(v, , sizeof(v));
scanf("%d%d", &m, &n);
for (int i = ; i <= m; i++) scanf("%s", s[i] + );
for (int i = ; i <= m - ; i++)
for (int j = ; j <= n - ; j++)
ok(i, j);//以(i,j)为起点的一次印
bool ans = ;
for (int i = ; i <= m; i++)
{
for (int j = ; j <= n; j++)
{
if (s[i][j] == '#' && !v[i][j]) { ans = ; break; }
//如果当前位置有墨印,但不可能被染色
}
if (!ans) break;
}
if (ans)printf("YES\n");
else printf("NO\n");
return ;
}
Forgery CodeForces - 1059B的更多相关文章
- CodeForces 1059B
Description Student Andrey has been skipping physical education lessons for the whole term, and now ...
- 2018SDIBT_国庆个人第六场
A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...
- Codeforces Round #514 (Div. 2) B - Forgery
这个题我一开始没思路,最后也没思路 2个小时一直没思路 本来还想解释题意的,写了半天发现解释的不是很清楚,你还是google翻译一下吧 这个题解法是这样的: 首先,给你图案里面有很多的点,每个点的周围 ...
- Codeforces Round #514 (Div. 2)
目录 Codeforces 1059 A.Cashier B.Forgery C.Sequence Transformation D.Nature Reserve(二分) E.Split the Tr ...
- Codeforces Round #668 (Div. 2)A-C题解
A. Permutation Forgery 题目:http://codeforces.com/contest/1405/problem/A 题解:这道题初看有点吓人,一开始居然想到要用全排序,没错我 ...
- Codeforces Round #668 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...
- ABP Zero示例项目登录报错“Empty or invalid anti forgery header token.”问题解决
ABP Zero项目,登录时出现如图"Empty or invalid anti forgery header token."错误提示的解决方法: 在 WebModule.cs的P ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- Nginx代理与反向代理、负载均衡实践
通过 Nginx 提供的反向代理和负载均衡功能,可以合理的完成业务的分配,提高网站的处理能力;同时利用缓存功能,还可以将不需要实时更新的动态页面输出结果,转化为静态网页形成缓存,从而提高网站的响应速度 ...
- 牛客 在其他数都出现k次的数组中找到出现1次的数
题目链接:https://www.nowcoder.com/practice/26e46f1f5e0d48c4b9ba13fe3e8d0ec6?tpId=101&tqId=33216& ...
- nmon使用及监控数据分析
https://blog.csdn.net/sean4m/article/details/79892387
- 阮一峰 ES6
阮一峰 ES6:http://es6.ruanyifeng.com/#docs/module
- [fw]LINUX中断描述符初始化
LINUX中断描述符初始化 @CopyLeft by ICANTH,I Can do ANy THing that I CAN THink!~ Author: WenHui, WuHan Univer ...
- git pull的时候发生冲突的解决方法之“error: Your local changes to the following files would be overwritten by merge”
今天在使用git pull 命令的时候发生了以下报错 目前git的报错提示已经相关友好了,可以直观的发现,这里可以通过commit的方式解决这个冲突问题,但还是想看看其他大佬是怎么解决这类问题的 在网 ...
- SET - 改变运行时参数
樊伟胜SYNOPSIS SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT } SET [ SESSION | LO ...
- SSH远程管理服务实战
目录 SSH远程管理服务实战 1.SSH基本概述 2.SSH相关命令 3.Xshell连接不上虚拟机 4.scp命令 5.sftp命令 6.SSH验证方式 7.SSH场景实践 8.SH安全优化 9.交 ...
- linux-ftp install
ftp安装 yum install vsftpd vi /etc/vsftpd/vsftpd.conf (可以先备份,但不要放在此目录下,不然启动vsftpd的时候 也会加载其备份文件,报启动错误,因 ...
- pycharm配色
setting-appearanse-theme-IntelliJ setting-Editer-color scheme-Default setting-Editer-color scheme-py ...