文章

35

粉丝

599

获赞

6

访问

294.5k

头像
大佬们的代码都是动归 弱鸡想问一下我的bfs该怎么改...
P1096
发布于2020年4月30日 19:50
阅读数 9.2k

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
struct node{
	int x,y;
}nod;
int n,m;
char ma[101][11];
bool inq[100][10]={false};
int xr[4]={0,0,1,-1};
int yr[4]={1,-1,0,0};

bool judge(int x,int y){
	if(x>=n||x<0||y>=m||y<0)return false;
	if(ma[x][y]=='*'||inq[x][y]==true)return false;
	return true;
}
int bfs(){
	int ans=0;
	queue<node> q;
	q.push(nod);
	while(!q.empty()){
		node top=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int newx=top.x+xr[i];
			int newy=top.y+yr[i];
			if(judge(newx, newy)){
				nod.x=newx,nod.y=newy;
				ans++;
				q.push(nod);
				inq[newx][newy]=true;
			}
		}
	}
	return ans;
}
int main() {
	while(cin>>n>>m){
	if(n>=1&&n<=100&&m>=1&&m<=10){
	for(int x=0;x<n;x++){
		getchar();
		for(int y...
登录查看完整内容


登录后发布评论

2 条评论
admin SVIP
2020年5月1日 19:51

这个一个状态压缩的动态规划问题,很裸的模板题,建议先看一下满分篇里的状态压缩的搜索问题laugh

赞(0)

chenziyi : 回复 admin: 谢谢 马上去看

2020年5月2日 23:40