FZU 2150 Fire Game --两点同步搜索
枚举两点,然后同步BFS,看代码吧,很容易懂的。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#define Mod 1000000007
using namespace std; struct Point
{
int x,y;
int step;
}S;
char mp[][];
int vis[][];
int n,m;
int lef;
int dx[] = {,,,-};
int dy[] = {,-,,};
queue<Point> que; bool OK(int nx,int ny)
{
if(nx < n && nx >= && ny < m && ny >= )
return true;
return false;
} int BFS()
{
int maxi = ;
while(!que.empty()) //同步搜索
{
int SIZE = que.size();
while(SIZE--)
{
Point tmp = que.front();
que.pop();
int nx = tmp.x;
int ny = tmp.y;
int step = tmp.step;
maxi = max(maxi,step);
Point now;
for(int k=;k<;k++)
{
int kx = nx + dx[k];
int ky = ny + dy[k];
if(!OK(kx,ky) || vis[kx][ky])
continue;
if(mp[kx][ky] == '#')
{
vis[kx][ky] = ;
now.x = kx;
now.y = ky;
now.step = step+;
que.push(now);
lef--;
}
}
}
}
if(lef == )
return maxi;
else
return -;
} int main()
{
int t,cs = ,i,j,k,h;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int cnt = ;
for(i=;i<n;i++)
{
scanf("%s",mp[i]);
for(j=;j<m;j++)
if(mp[i][j] == '#')
cnt++;
}
int flag = ;
int tag = Mod;
for(i=;i<n;i++) //第一个点
{
for(j=;j<m;j++)
{
if(mp[i][j] == '#')
{
for(k=i;k<n;k++) //第二个点
{
for(h=(k==i?j:);h<m;h++)
{
if(mp[k][h] == '#')
{
memset(vis,,sizeof(vis));
S.x = i,S.y = j,S.step = ;
que.push(S);
lef = cnt-;
vis[i][j] = ;
if(!(i==k&&j==h))
{
S.x = k,S.y = h,S.step = ;
que.push(S);
vis[k][h] = ;
lef--;
}
int res = BFS();
if(res != -)
{
flag = ;
tag = min(tag,res);
}
}
}
}
}
}
}
if(flag)
printf("Case %d: %d\n",cs++,tag);
else
printf("Case %d: -1\n",cs++);
}
return ;
}
FZU 2150 Fire Game --两点同步搜索的更多相关文章
- FZU 2150 Fire Game(点火游戏)
FZU 2150 Fire Game(点火游戏) Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description - 题目描述 ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- fzu 2150 Fire Game 【身手BFS】
称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...
- FZU 2150 fire game (bfs)
Problem 2150 Fire Game Accept: 2133 Submit: 7494Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- FZU 2150 Fire Game (暴力BFS)
[题目链接]click here~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...
- FZU 2150 Fire Game 广度优先搜索,暴力 难度:0
http://acm.fzu.edu.cn/problem.php?pid=2150 注意这道题可以任选两个点作为起点,但是时间仍足以穷举两个点的所有可能 #include <cstdio> ...
- FZU 2150 Fire Game 【两点BFS】
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...
- (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 ,Floyd。
Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...
随机推荐
- TCP中close和shutdown之间的区别
该图片截取自<<IP高效编程-改善网络编程的44个技巧>>,第17个技巧. 如果想验证可以写个简单的网络程序,分别用close和shutdown来断开连接,然后用tcpdum ...
- rails provide与content_for的区别
页面渲染时:provide先执行,但找到一个provide之后就不再查找 content_for 顺序执行,在哪个位置,就等之前的渲染完后才执行.但是要等到所有的content被查找完后一块返回,也就 ...
- SharePoint 页面中添加.Net代码
今天整理资料,看到一个非常有意思的截图,可以在SharePoint页面库里的页面中,添加.Net代码,只需修改一下相应应用程序的web.config文件,即可: 在web.config里面的<P ...
- 2015年第8本(英文第7本):the city of ember 微光城市
书名:the City of Ember(中文名:微光城市) 作者:Jeanne DuPrau 单词数:6.2万 不重复单词数:未知 首万词不重复单词数:未知 蓝思值:未知 阅读时间:2015年4月2 ...
- Android Activity使用拾遗
一.onWindowFocusChanged 有时我们需要测量一个Activity多长时间才能显示出来,那么在代码中打点计时的时机选在哪儿呢?在onCreate和onResume执行完成后,Activ ...
- Windows7下Blend for Visual Studio 2012使用问题
目前开发的系统里很多控件样式和动画比较复杂,应该是之前同事用Blend做的,这种神器不用太浪费了,自己也准备试试. 系统环境Windows7+Visual Studio 2012 1.Windows7 ...
- iOS之UI--自定义IOS的HYCheckBox源码的使用
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Intelli IDEA ultimate破解方法
今天装了个Intelli IDEA,ultimate版本,使用网上方法破解了,破解方法参考网址 http://appcode.aliapp.com/idea.jsp Intelli IDEA有个vi ...
- Node.js之Promise维护(同步)多个回调(异步)状态
金天:学习一个新东西,就要持有拥抱的心态,如果固守在自己先前的概念体系,就会有举步维艰的感觉..NET程序员初用node.js最需要适应的就是异步开发, 全是异步,常规逻辑下遍历列表都是异步,如何保证 ...
- select_tag in rails about selected not change and onchange()
make it more easy after http://www.cnblogs.com/juandx/p/4058399.html 1 if you want the selected is ...