Plus from Picture

2024-09-04 23:32
文章标签 plus picture

本文主要是介绍Plus from Picture,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Plus from Picture

You have a given picture with size w×hw×h. Determine if the given picture has a single “+” shape or not. A “+” shape is described below:
A “+” shape has one center nonempty cell.
There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
All other cells are empty.
Find out if the given picture has single “+” shape.
Input
The first line contains two integers hh and ww (1≤h1≤h, w≤500w≤500) — the height and width of the picture.
The ii-th of the next hh lines contains string sisi of length ww consisting “.” and “" where “.” denotes the empty space and "” denotes the non-empty space.
Output
If the given picture satisfies all conditions, print “YES”. Otherwise, print “NO”.
You can output each letter in any case (upper or lower).
Examples

Examples
Input
Copy
5 6
......
..*...
.****.
..*...
..*...
Output
Copy
YES
Input
Copy
3 5
..*..
****.
.*...
Output
Copy
NO
Input
Copy
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
Copy
NO
Input
Copy
5 6
..**..
..**..
******
..**..
..**..
Output
Copy
NO
Input
Copy
3 7
.*...*.
***.***
.*...*.
Output
Copy
NO
Input
Copy
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
Copy
NO
Note

In the first example, the given picture contains one "+".

In the second example, two vertical branches are located in a different column.

In the third example, there is a dot outside of the shape.

In the fourth example, the width of the two vertical branches is 22.

In the fifth example, there are two shapes.

In the sixth example, there is an empty space inside of the shape.

一开始以为是一道dfs题然后找几个区域块的那种题后来仔细读题发现是一道可以暴力的题 题意一个二维字符数组 要求这个二维数组里只存在一个构成”十“形状的图像.表示空白*来表示填充的字符。 思路 既然要只存在一个十那么我们只需要找到一个十并把它清除掉 如果说还是存在*那么就是不符合题意因为这个图型里只允许存在一个*组成的十并且没有其它多余的*所以我们只需要找到十字的中心然后把这个十删除 然后再便利一次如果还存在*那么就不和题否则就合题
#include <iostream>
#include <cmath>
#include<set>
#include <algorithm>
#include<string>
#include<string.h>
using namespace std;
int a[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char v[1000][1000];
void clearr(int x,int y)
{v[x][y]='.';for(int i=0;i<4;i++){int x1=x,y1=y;while(v[x1+a[i][0]][y1+a[i][1]]=='*'){v[x1+a[i][0]][y1+a[i][1]]='.';x1+=a[i][0],y1+=a[i][1];}}}
int main()
{string s;char ss[10000];int n,m,b[1000],flag1=0;while(cin>>m>>n){memset(v,0,sizeof(v));for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){cin>>v[i][j];}}flag1=1;for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){if(v[i][j]=='*'&&v[i+1][j]=='*'&&v[i-1][j]=='*'&&v[i][j+1]=='*'&&v[i][j-1]=='*'&&i+1<=m&&i-1>=1&&j+1<=n&&j-1>=1){flag1=0;clearr(i,j);goto l;}}}l:int flag=0;for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){if(v[i][j]=='*'){flag=1;}}}if(flag1==1||flag)cout<<"NO"<<endl;elsecout<<"YES"<<endl;}}

这篇关于Plus from Picture的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1137343

相关文章

mybatis-plus分表实现案例(附示例代码)

《mybatis-plus分表实现案例(附示例代码)》MyBatis-Plus是一个MyBatis的增强工具,在MyBatis的基础上只做增强不做改变,为简化开发、提高效率而生,:本文主要介绍my... 目录文档说明数据库水平分表思路1. 为什么要水平分表2. 核心设计要点3.基于数据库水平分表注意事项示例

MyBatis-Plus逻辑删除实现过程

《MyBatis-Plus逻辑删除实现过程》本文介绍了MyBatis-Plus如何实现逻辑删除功能,包括自动填充字段、配置与实现步骤、常见应用场景,并展示了如何使用remove方法进行逻辑删除,逻辑删... 目录1. 逻辑删除的必要性编程1.1 逻辑删除的定义1.2 逻辑删php除的优点1.3 适用场景2.

MyBatis-Plus使用动态表名分表查询的实现

《MyBatis-Plus使用动态表名分表查询的实现》本文主要介绍了MyBatis-Plus使用动态表名分表查询,主要是动态修改表名的几种常见场景,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录1. 引入依赖2. myBATis-plus配置3. TenantContext 类:租户上下文

MyBatis Plus中执行原生SQL语句方法常见方案

《MyBatisPlus中执行原生SQL语句方法常见方案》MyBatisPlus提供了多种执行原生SQL语句的方法,包括使用SqlRunner工具类、@Select注解和XML映射文件,每种方法都有... 目录 如何使用这些方法1. 使用 SqlRunner 工具类2. 使用 @Select 注解3. 使用

MyBatis Plus大数据量查询慢原因分析及解决

《MyBatisPlus大数据量查询慢原因分析及解决》大数据量查询慢常因全表扫描、分页不当、索引缺失、内存占用高及ORM开销,优化措施包括分页查询、流式读取、SQL优化、批处理、多数据源、结果集二次... 目录大数据量查询慢的常见原因优化方案高级方案配置调优监控与诊断总结大数据量查询慢的常见原因MyBAT

MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决

《MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决》MyBatis默认开启一级缓存,同一事务中循环调用查询方法时会重复使用缓存数据,导致获取的序列主键值均为1,... 目录问题原因解决办法如果是存储过程总结问题myBATis有如下代码获取序列作为主键IdMappe

MyBatis Plus实现时间字段自动填充的完整方案

《MyBatisPlus实现时间字段自动填充的完整方案》在日常开发中,我们经常需要记录数据的创建时间和更新时间,传统的做法是在每次插入或更新操作时手动设置这些时间字段,这种方式不仅繁琐,还容易遗漏,... 目录前言解决目标技术栈实现步骤1. 实体类注解配置2. 创建元数据处理器3. 服务层代码优化填充机制详

mybatis-plus如何根据任意字段saveOrUpdateBatch

《mybatis-plus如何根据任意字段saveOrUpdateBatch》MyBatisPlussaveOrUpdateBatch默认按主键判断操作类型,若需按其他唯一字段(如agentId、pe... 目录使用场景方法源码方法改造首先在service层定义接口service层接口实现总结使用场景my

MyBatis-plus处理存储json数据过程

《MyBatis-plus处理存储json数据过程》文章介绍MyBatis-Plus3.4.21处理对象与集合的差异:对象可用内置Handler配合autoResultMap,集合需自定义处理器继承F... 目录1、如果是对象2、如果需要转换的是List集合总结对象和集合分两种情况处理,目前我用的MP的版本

MyBatis-Plus 与 Spring Boot 集成原理实战示例

《MyBatis-Plus与SpringBoot集成原理实战示例》MyBatis-Plus通过自动配置与核心组件集成SpringBoot实现零配置,提供分页、逻辑删除等插件化功能,增强MyBa... 目录 一、MyBATis-Plus 简介 二、集成方式(Spring Boot)1. 引入依赖 三、核心机制