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 ...
随机推荐
- Gson字符串转换对象数组
public class Input { private String title; private int formId; private String content; public String ...
- flask扩展系列之 - 访问速度限制
flask-limiter 是一个对客户端的访问速率进行限制的flask扩展.可以自定义一些访问的(速度)限制条件来把那些触发限制的请求拒之门外.一般常用来进行对爬虫的限制. 下面就常见的用法,举了一 ...
- python自带的split VS numpy中的split比较
Python split() 通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则分隔 num+1 个子字符串 str1.split() 里面的参数,可以是空格,逗号,字符串啥的,具体应用与 ...
- mysql 【常用sql】
修改过mysql数据库字段内容默认值为当前时间 --添加CreateTime 设置默认时间 CURRENT_TIMESTAMP ALTER TABLE `table_name` ADD COLUMN ...
- python中变量的命令规制及变量的赋值方式
文章结构: 一.python中变量的命名规则 二.变量赋值的三种方式 三.python的垃圾回收机制 一.Python中变量的 ...
- Mybatis+Springmvc+Spring整合常用的配置文件
1.创建web项目 2.导入mabatis spring springnvc 需要的jar包 3.创建mybatis,spring,springmvc的配置文件 (1)web.xml配置文件 < ...
- wpf 查找控件
public List<T> GetChildObjects<T>(DependencyObject obj, Type typename) where T : Framewo ...
- 最新版WinRAR5.61去广告代码教程分享(仅供学习交流)
最新版WinRAR5.61去广告代码教程分享(仅供学习交流) 第一步:到WinRAR官网www.rarlab.com下载自己需要的版本,选择Chinese Simplified 64bit 安装即可. ...
- 转载:php excel 的处理
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- Elasticsearch 分布式文档存储
shard = hash(routing) % number_of_primary_shards决定文档在哪个分片上,routing 是一个可变值,默认是文档的 _id ,也可以设置成一个自定义的值. ...