设为首页 加入收藏

TOP

UVA 11624 Fire!(二次BFS)
2014-11-23 20:16:34 来源: 作者: 【 】 浏览:7
Tags:UVA 11624 Fire 二次 BFS

先对火BFS一次,求出每个点的最小着火时间。

再对人BFS一次,求出走到边界的最少时间。

#include 
#include 
#include 
using namespace std;
int n,m,bz[1005][1005],qihuo[1005][1005];
char map[1005][1005];
int h[4][2]={-1,0,1,0,0,-1,0,1};
struct point
{
	int x,y,step;
};
queue q;
void bfs_huo()
{
	int i,j,x,y;
	point t,tt;
	while(!q.empty())
	{
		t=q.front(); q.pop();
		for(i=0;i<4;i++)
		{
			x=t.x+h[i][0]; y=t.y+h[i][1];
			if(x>=0&&x=0&&y=0&&x=0&&y>nn;
	while(nn--)
	{
		cin>>n>>m;
		while(!q.empty()) q.pop();
		memset(bz,0,sizeof(bz));
		for(i=0;i>map[i][j];   qihuo[i][j]=1000000000; //    
			if(map[i][j]=='J') {s.x=i; s.y=j; s.step=0;}
			if(map[i][j]=='F') {t.x=i; t.y=j; t.step=0; q.push(t); bz[i][j]=1; qihuo[i][j]=0;}
		}
		bfs_huo();
		memset(bz,0,sizeof(bz));
		int ans=bfs_men(s);
		if(ans>=0) cout< 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU--杭电--1208--Pascal's T.. 下一篇hdu 2817 A sequence of numbers ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C 内存管理 | 菜鸟教 (2025-12-26 20:20:37)
·如何在 C 语言函数中 (2025-12-26 20:20:34)
·国际音标 [ç] (2025-12-26 20:20:31)
·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)