CF1182B Plus from Picture 题解( CodeForces)

题目
原题

题意

给你一个 n ∗ m n*m nm的地图(只包含*,.)。
问你有没有符合条件的图形

  • 中心点为*
  • 上下左右四个方向都有一个或多个连续的 *
  • 除以上各点之外,整张地图均为 .

看到数据范围就知道,暴力就好了。

思路

首先记录一下*的数量。
f o r for for循环枚举一下符合条件的图。找到就直接结束程序

代码

#include<bits/stdc++.h>
#include<cstring>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<map>
#define ll long long
using namespace std;
const int N=1e5+10;
const int M=2023;
const int inf=0x3f3f3f3f;
int n,m,num,vis[514][514];
char a[514][514];
int dx[]={0,0,1,-1},ff;
int dy[]={1,-1,0,0};
void dfs(int x,int y,int step,int fx)
{
	for(int i=0;i<4;i++)
	{
		int nx=x,ny=y;
		while(1)
		{
			nx+=dx[i];
			ny+=dy[i];
			if(nx>=1 and nx<=n and ny>=1 and ny<=m and a[nx][ny]=='*')
			{
				vis[nx][ny]=1;
				step++;//记录数量
			}
			else
			{
				break;
			}
		}
	}
	if(step+1==num)//除以上各点之外,整张地图均为'.'
	{
		cout<<"YES";
		ff=1;//记录答案
		exit(0);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='*')//记录数量
			{
				num++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			bool flag=0;
			if(a[i][j]=='*' and !vis[i][j])
			{
				for(int k=0;k<4;k++)
				{
					int nx,ny;
					nx=i+dx[k];
					ny=j+dy[k];
					if(nx>=1 and nx<=n and ny>=1 and ny<=m)
					{
						if(a[nx][ny]!='*')//首先上下左右都要是'*'
						{
							flag=1;
							break;
						}
					}
					else//处于边缘地带,不可能上下左右
					{
						flag=1
					}
				}
				if(flag==0)
				{
					dfs(i,j,0,0);//暴力
				}
				if(ff==1)
				{
					return 0;//直接结束
				}
			}
		}
	}
	cout<<"NO";
	return 0;
}

事实上这道题还是有点水的

AC记录

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值