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大数据量查询慢原因分析及解决

《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. 引入依赖 三、核心机制

Mybatis-Plus 3.5.12 分页拦截器消失的问题及快速解决方法

《Mybatis-Plus3.5.12分页拦截器消失的问题及快速解决方法》作为Java开发者,我们都爱用Mybatis-Plus简化CRUD操作,尤其是它的分页功能,几行代码就能搞定复杂的分页查询... 目录一、问题场景:分页拦截器突然 “失踪”二、问题根源:依赖拆分惹的祸三、解决办法:添加扩展依赖四、分页

MyBatis-Plus 自动赋值实体字段最佳实践指南

《MyBatis-Plus自动赋值实体字段最佳实践指南》MyBatis-Plus通过@TableField注解与填充策略,实现时间戳、用户信息、逻辑删除等字段的自动填充,减少手动赋值,提升开发效率与... 目录1. MyBATis-Plus 自动赋值概述1.1 适用场景1.2 自动填充的原理1.3 填充策略

mybatis-plus QueryWrapper中or,and的使用及说明

《mybatis-plusQueryWrapper中or,and的使用及说明》使用MyBatisPlusQueryWrapper时,因同时添加角色权限固定条件和多字段模糊查询导致数据异常展示,排查发... 目录QueryWrapper中or,and使用列表中还要同时模糊查询多个字段经过排查这就导致只要whe

MyBatis-Plus通用中等、大量数据分批查询和处理方法

《MyBatis-Plus通用中等、大量数据分批查询和处理方法》文章介绍MyBatis-Plus分页查询处理,通过函数式接口与Lambda表达式实现通用逻辑,方法抽象但功能强大,建议扩展分批处理及流式... 目录函数式接口获取分页数据接口数据处理接口通用逻辑工具类使用方法简单查询自定义查询方法总结函数式接口