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升级为Mybatis-Plus的详细过程

《将Mybatis升级为Mybatis-Plus的详细过程》本文详细介绍了在若依管理系统(v3.8.8)中将MyBatis升级为MyBatis-Plus的过程,旨在提升开发效率,通过本文,开发者可实现... 目录说明流程增加依赖修改配置文件注释掉MyBATisConfig里面的Bean代码生成使用IDEA生

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Spring Boot结成MyBatis-Plus最全配置指南

《SpringBoot结成MyBatis-Plus最全配置指南》本文主要介绍了SpringBoot结成MyBatis-Plus最全配置指南,包括依赖引入、配置数据源、Mapper扫描、基本CRUD操... 目录前言详细操作一.创建项目并引入相关依赖二.配置数据源信息三.编写相关代码查zsRArly询数据库数

mybatis-plus分页无效问题解决

《mybatis-plus分页无效问题解决》本文主要介绍了mybatis-plus分页无效问题解决,原因是配置分页插件的版本问题,旧版本和新版本的MyBatis-Plus需要不同的分页配置,感兴趣的可... 昨天在做一www.chinasem.cn个新项目使用myBATis-plus分页一直失败,后来经过多方

mybatis-plus 实现查询表名动态修改的示例代码

《mybatis-plus实现查询表名动态修改的示例代码》通过MyBatis-Plus实现表名的动态替换,根据配置或入参选择不同的表,本文主要介绍了mybatis-plus实现查询表名动态修改的示... 目录实现数据库初始化依赖包配置读取类设置 myBATis-plus 插件测试通过 mybatis-plu

MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析

《MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析》本文将详细讲解MyBatis-Plus中的lambdaUpdate用法,并提供丰富的案例来帮助读者更好地理解和应... 目录深入探索MyBATis-Plus中Service接口的lambdaUpdate用法及示例案例背景

MyBatis-Plus中静态工具Db的多种用法及实例分析

《MyBatis-Plus中静态工具Db的多种用法及实例分析》本文将详细讲解MyBatis-Plus中静态工具Db的各种用法,并结合具体案例进行演示和说明,具有很好的参考价值,希望对大家有所帮助,如有... 目录MyBATis-Plus中静态工具Db的多种用法及实例案例背景使用静态工具Db进行数据库操作插入

springboot3.4和mybatis plus的版本问题的解决

《springboot3.4和mybatisplus的版本问题的解决》本文主要介绍了springboot3.4和mybatisplus的版本问题的解决,主要由于SpringBoot3.4与MyBat... 报错1:spring-boot-starter/3.4.0/spring-boot-starter-

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

SpringBoot基于MyBatis-Plus实现Lambda Query查询的示例代码

《SpringBoot基于MyBatis-Plus实现LambdaQuery查询的示例代码》MyBatis-Plus是MyBatis的增强工具,简化了数据库操作,并提高了开发效率,它提供了多种查询方... 目录引言基础环境配置依赖配置(Maven)application.yml 配置表结构设计demo_st