foj 2150 bfs
题意:
给定一个平面图 . 为空地(不着火) # 为草
开始可以选1-2个草堆点燃,每隔一秒会把上下左右的草引燃(开始时间为0秒)
问把所有草烧光的最少时间
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; const int INF=;
inline int min(int a,int b){return a<b?a:b;}
inline int max(int a,int b){return a>b?a:b;} char mp[][];
int v[][];
int R,C;
int dir[][]={,,,-,,,-,}; struct Node{
int x,y;
Node(int x=,int y=):x(x),y(y){}
}t1,t2; int bfs(int a,int b,int c,int d)
{
int i,j,ans=;
for(i=;i<;i++) for(j=;j<;j++) v[i][j]=INF;
queue<Node> Q;
Q.push(Node(a,b));
Q.push(Node(c,d));
v[a][b]=v[c][d]=;
while(!Q.empty())
{
t1=Q.front();Q.pop();
for(i=;i<;i++)
{
t2.x=t1.x+dir[i][];t2.y=t1.y+dir[i][];
if(mp[t2.x][t2.y]=='#' && v[t2.x][t2.y]>v[t1.x][t1.y]+)
{
Q.push(t2);v[t2.x][t2.y]=v[t1.x][t1.y]+;
}
}
}
for(i=;i<=R;i++)
{
for(j=;j<=C;j++)
if(mp[i][j]=='#') ans=max(ans,v[i][j]);
}
return ans;
} int Slove()
{
int Min=INF;
int i,j,k,m;
for(i=;i<=R;i++)
{
for(j=;j<=C;j++)
{
if(mp[i][j]=='#')
{
for(k=i;k<=R;k++)
{
for(m=;m<=C;m++)
if(mp[k][m]=='#')
{
if(i==k && j==m) continue;
Min=min(Min,bfs(i,j,k,m));
}
}
}
}
}
return Min==INF?-:Min;
}
int main()
{
int cnt,t,Icase,i,j;
scanf("%d",&t);
for(Icase=;Icase<=t;Icase++)
{
cnt=;
scanf("%d %d",&R,&C);
for(i=;i<=R;i++)
{
getchar();
for(j=;j<=C;j++)
{
scanf("%c",&mp[i][j]);
if(mp[i][j]=='#') cnt++;
}
}
if(cnt<=) {printf("Case %d: 0\n",Icase);continue;}
for(i=;i<=R;i++) mp[i][]=mp[i][C+]='.';
for(i=;i<=C;i++) mp[][i]=mp[R+][i]='.';
printf("Case %d: %d\n",Icase,Slove());
}
return ;
}
foj 2150 bfs的更多相关文章
- foj 2150 Fire Game(bfs暴力)
Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M ...
- FZU - 2150 bfs [kuangbin带你飞]专题一
题意:两个人玩很变态的游戏,将一个草坪的某两个点点燃,点燃的草坪可以向上下左右四个方向扩散,问能否将整块草坪上面的草都点燃.如果能,输出最短时间(^_^他们就能玩更变态的游戏了),如果不能,输出-1. ...
- fzu 2150(bfs)
Problem 2150 Fire Game Accept: 693 Submit: 2657 Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- fzu 2150 Fire Game 【身手BFS】
称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...
- (FZU 2150) Fire Game (bfs)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...
- FZU 2150 fire game (bfs)
Problem 2150 Fire Game Accept: 2133 Submit: 7494Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- Fire Game FZU - 2150 (bfs)
Problem 2150 Fire Game Accept: 3772 Submit: 12868Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- FZU 2150 Fire Game (暴力BFS)
[题目链接]click here~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...
随机推荐
- 前缀树,trie树
前缀树: 假设一个字符串数组,“abcd”,"bcd","gef" , 构建一颗树,字母是在路径上,节点上最基本的存储的信息包括: 以这个节点结尾的 字符串的数 ...
- tcp 高性能服务, netty,mqtt
1. io 线程不要有比较长的服务. 全部异步化. [1] netty 权威指南上只是说业务复杂时派发到业务线程池种. 共用的线程池最好都轻量. 多层线程池后, 下层的可以进行隔离. 这个是 mqtt ...
- iOS 多线程编程
参考文章: iOS多线程编程之NSThread的使用http://blog.csdn.net/totogo2010/article/details/8010231 iOS多线程编程之NSOperati ...
- 119. Pascal's Triangle II@python
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- 【构造题 贪心】cf1041E. Tree Reconstruction
比赛时候还是太慢了……要是能做快点就能上分了 Monocarp has drawn a tree (an undirected connected acyclic graph) and then ha ...
- CentOS7 安装操作命令
#timedatectl set-timezone Asia/Shanghai 关闭SELinux vi /etc/sysconfig/selinux #SELINUX=enforcing SELIN ...
- 【php】expose_php 作用
php.ini expose_php = On expose_php = Off
- day 37 MySQL行(记录)的详细操作
MySQL行(记录)的详细操作 阅读目录 一 介绍 二 插入数据INSERT 三 更新数据UPDATE 四 删除数据DELETE 五 查询数据SELECT 六 权限管理 一 介绍 MySQL数据操 ...
- graph-Kruskal-algorithm
并查集是一种树型的数据结构,用于处理一些不相交集合(Disjoint Sets)的合并及查询问题.主要操作:1. 初始化:每个点所在集合初始化为其自身.2. 查找:查找元素所在的集合,即根节点.3. ...
- 二叉排序树:POJ2418-Hardwood Species(外加字符串处理)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Description Hardwoods are the botanical gr ...