Forest

You’re a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.

The forest

The Biridian Forest is a two-dimensional grid consisting of r r r rows and c c c columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.

The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here’s an example of such grid (from the first example):

0^0


```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=1007;
char a[N][N];
int n,m,dis[N][N],sx,sy,tx,ty,ans;
const int x_[4]={1,-1,0,0};
const int y_[4]={0,0,1,-1};
struct node{
	int x,y,d;
};
queue<node>q;
void bfs(int tx,int ty){
	q.push(node{tx,ty,0});
	dis[tx][ty]=-1;
	int x,y;
	while(!q.empty()){
		node now=q.front();q.pop();
		for(int i=0;i<4;i++){
			x=now.x+x_[i];
			y=now.y+y_[i];
			dis[x][y]=now.d+1;
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		if(a[i][j]=='S'){sx=i;sy=j;}
		if(a[i][j]=='E'){tx=i;ty=j;}
	}
	bfs(tx,ty);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
		if(dis[i][j]!=0&&dis[i][j]<=dis[sx][sy]&&a[i][j]>='0'&&a[i][j]<='9')ans+=a[i][j]-'0';
	cout<<ans;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值