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 ...
随机推荐
- 「C语言」Windows+EclipseCDT下的C语言开发环境准备
之前写过一篇 「C语言」在Windows平台搭建C语言开发环境的多种方式 ,讨论了如何在Windows下用DEV C++.EclipseCDT.VisualStudio.Sublime Test.Cl ...
- Java正则表达式实用教程
java.util.regex是一个用正则表达式所订制的模式来对字符串进行匹配工作的类库包.java.util.regex包主要包括以下三个类:Pattern.Matcher和PatternSynta ...
- [Tips] Useful link ... on going
1. CSS Bootstrap http://getbootstrap.com/ Bootstrap 中文文档 http://getbootstrap.com/2.3.2/ 最全的 Twitter ...
- CRM 2013 Reporting Extensions for SSRS 安装及问题解决
说明一下 Reporting Extensions for SSRS 安装过程. 安装目录在安装目录下 SrsDataConnector 下.如果是CRM 2013安装中运行,可以跳过此步. 此外在说 ...
- Android动画translate坐标图
X坐标图示: Y坐标图示:
- 部分博文目录索引(C语言+算法)
今天将本博客的部分文章建立一个索引,方便大家进行阅读,当然每一类别中的文章都会持续的添加和更新(PS:博文主要使用C语言) 博客地址:http://www.cnblogs.com/archimedes ...
- UITabBarController QQ
AppDelegate.m #import "AppDelegate.h" #import "FirstViewController.h" #import &q ...
- HTML5 -1- 简介
在介绍HTML5之前我们应该先了解一下HTML5 我想从下面开始简单了解一下HTML5 什么是HTML5??? HTML5 即HTML 5.0 版本 正式制定时间是在2014年 遵循着移动先行(前四个 ...
- 高质量c/c++里的strcpy()
已知strcpy函数的原型是: char * strcpy(char * strDest,const char * strSrc); 1.不调用库函数,实现strcpy函数. ...
- Solr与HBase架构设计
摘要:本篇是本人在做一个大数据项目时,对于系统架构的一点总结,如何在保证存储量的情况下,又能保证数据的检索速度. 前提: Solr.SolrCloud提供了一整套的数据检索方案,HBase提 ...