文章

28

粉丝

0

获赞

47

访问

13.4k

头像
生化武器 题解:BFS
P1126
发布于 2026年8月
阅读数 559

最多搜到距离为t就不要往下搜了。 判断是刚好满、未满、还是在t秒之前就满了。

#include<bits/stdc++.h>
using namespace std;
struct Node{
	int x,y,second;
};
const int dx[4] = {-1,1,0,0};
const int dy[4] = {0,0,-1,1};

int main(){
	int n,m,t;
	while(cin>>n>>m>>t){
		vector<string> maze;
		vector<vector<bool> > visited(n,vector<bool>(m,false));
		bool find_s=false;
		int sx,sy;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			maze.push_back(s);
			if(!find_s){
				for(int j=0;j<m;j++){
					if(s[j]=='*'){
						find_s=true;
						sx=i;
						sy=j;
						visited[i][j]=true;
						maze[i][j]='#';
					}
				}	
			}
		}
		queue<Node > q;
		Node s_dot={sx,sy,0};
		q.push(s_dot);
		bool can=true;
		int cur_second=0; 
		while(!q.empty()){			
			Node old_dot=q.front();
			q.pop();
			if(old_dot.second==t){
				cur_second=t;
				break;
			} 
			for(int i=0;i<4;i++){
				int new_x=old_dot.x+dx[i],new_y=old_dot.y+dy...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发