kuangbin专题 专题一 简单搜索 Fire Game FZU - 2150
题目链接:https://vjudge.net/problem/FZU-2150
题意:’ . '代表火无法烧着的地方,‘ # ’表示草,火可以烧着。选择任意两个‘ # ’(可以两个都选同一个 ‘ # ’),火会蔓延,每过1个时间消耗,向四周蔓延。问:能不能把草全部烧完,可以的话得出最短时间,否则输出 -1。
思路:bfs,枚举所有点火情况就OK了,直接看代码吧。
- #include <iostream>
- #include <cstring>
- #include<vector>
- #include<string>
- #include <cmath>
- #include <map>
- #include <queue>
- #include <algorithm>
- using namespace std;
- #define inf (1LL << 31) - 1
- #define rep(i,j,k) for(int i = (j); i <= (k); i++)
- #define rep__(i,j,k) for(int i = (j); i < (k); i++)
- #define per(i,j,k) for(int i = (j); i >= (k); i--)
- #define per__(i,j,k) for(int i = (j); i > (k); i--)
- const int N = ;
- int mv_x[] = { , , , - };
- int mv_y[] = { , -, , };
- int x[]; //草的x
- int y[]; //草的y
- int l; //几颗草
- char mp[N][N]; //原始地图
- char cp_mp[N][N]; //原始地图副本,用于bfs
- bool vis[N][N];
- int ans; //答案
- int n, m;
- struct node{
- int x, y, c;
- node(){}
- node(int o, int oo, int ooo){
- x = o;
- y = oo;
- c = ooo;
- }
- };
- inline void input(){
- l = ;
- rep(i, , n) rep(j, , m){
- cin >> mp[i][j];
- //记录下所有草
- if (mp[i][j] == '#'){
- x[l] = i;
- y[l++] = j;
- }
- }
- }
- //每种情况前,初始化函数
- inline void init_vis_And_cp_mp(){
- memset(vis, , sizeof(vis));
- memcpy(cp_mp, mp, sizeof(mp));
- }
- //边界
- inline bool check(int x, int y){
- return x >= && x <= n && y >= && y <= m;
- }
- //检查草是否都烧完
- bool all_Fired(){
- rep(i, , n) rep(j, , m){
- if (cp_mp[i][j] == '#' && !vis[i][j]) return false;
- }
- return true;
- }
- void bfs(int x1, int y1, int x2, int y2){
- queue<node> que;
- //标记两个点火源
- vis[x1][y1] = true;
- vis[x2][y2] = true;
- //放入队列
- node a1(x1, y1, );
- node a2(x2, y2, );
- que.push(a1);
- que.push(a2);
- int tmp_ans = ;
- while (!que.empty()){
- node tmp = que.front();
- que.pop();
- tmp_ans = max(tmp_ans, tmp.c); //这里是得出能烧到的草的最后时间
- rep__(p, , ){
- int dx = tmp.x + mv_x[p];
- int dy = tmp.y + mv_y[p];
- //没越界,没被访问过,是草
- if (check(dx, dy) && !vis[dx][dy] && cp_mp[dx][dy] == '#'){
- vis[dx][dy] = true;
- node k(dx, dy, tmp.c + );
- que.push(k);
- }
- }
- }
- //全部烧完才能算一个答案
- if (all_Fired()) ans = min(ans, tmp_ans);
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie();
- int T;
- cin >> T;
- rep(o, , T){
- cin >> n >> m;
- input();
- ans = inf; //
- //枚举点火情况
- rep__(i, , l ) rep__(j, i, l){
- init_vis_And_cp_mp(); //每种情况前,初始化函数
- bfs(x[i], y[i], x[j], y[j]); //两个点火源
- }
- // cout << "Case 1: 1" << endl;
- cout << "Case " << o << ": " << (ans == inf ? - : ans) << endl;
- }
- return ;
- }
kuangbin专题 专题一 简单搜索 Fire Game FZU - 2150的更多相关文章
- (广搜)Fire Game -- FZU -- 2150
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/I Fire Game Time Limit:1000MS ...
- kuangbin专题 专题一 简单搜索 Fire! UVA - 11624
题目链接:https://vjudge.net/problem/UVA-11624 题意:一个迷宫,可能有一个或者多个地方着火了,每过1个时间消耗,火会向四周蔓延,问Joe能不能逃出迷宫,只要走出迷宫 ...
- kuangbin专题总结一 简单搜索
A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...
- Fire Game FZU - 2150 (bfs)
Problem 2150 Fire Game Accept: 3772 Submit: 12868Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- 搜索入门_简单搜索bfs dfs大杂烩
dfs题大杂烩 棋盘问题 POJ - 1321 和经典的八皇后问题一样. 给你一个棋盘,只有#区域可以放棋子,同时同一行和同一列只能有一个棋子. 问你放k个棋子有多少种方案. 很明显,这是搜索题. ...
- [kuangbin带你飞]专题一 简单搜索
ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题 328 / 854 Problem B POJ 2251 Dungeon Ma ...
- 简单搜索 kuangbin C D
C - Catch That Cow POJ - 3278 我心态崩了,现在来回顾很早之前写的简单搜索,好难啊,我怎么写不出来. 我开始把这个写成了dfs,还写搓了... 慢慢来吧. 这个题目很明显是 ...
- ElasticSearch 5学习(4)——简单搜索笔记
空搜索: GET /_search hits: total 总数 hits 前10条数据 hits 数组中的每个结果都包含_index._type和文档的_id字段,被加入到_source字段中这意味 ...
- nyoj 284 坦克大战 简单搜索
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284 题意:在一个给定图中,铁墙,河流不可走,砖墙走的话,多花费时间1,问从起点到终点至少 ...
随机推荐
- MVC 用基架创建Controller,通过数据库初始化器生成并播种数据库
1 创建MVC应用程序 2 在Model里面创建实体类 using System; using System.Collections.Generic; using System.Linq; using ...
- AY的Dapper研究学习-继续深入-C#开发-aaronyang技术分享
原文:AY的Dapper研究学习-继续深入-C#开发-aaronyang技术分享 ====================www.ayjs.net 杨洋 wpfui.com ...
- 在WPF中减少逻辑与UI元素的耦合
原文:在WPF中减少逻辑与UI元素的耦合 在WPF中减少逻辑与UI元素的耦合 周银辉 1, 避免在逻辑中引用界面元素,别把后台数据强加给UI 一个糟糕的案例 比如说主界 ...
- delphi中使用词霸2005的动态库XdictGrb.dll实现屏幕取词
近日来,在网上发现关于屏幕取词技术的捷径,搜索很长时间,发现实现方式以VB出现的居多,但是通过Delphi来实现的却好象没有看到,自己参考着VB的相关代码琢磨了一下通过delphi来实现的方式. 其实 ...
- Win8Metro(C#)数字图像处理--2.14Prewitt 边缘检测
原文:Win8Metro(C#)数字图像处理--2.14Prewitt 边缘检测 [函数名称] 图像Prewitt边缘检测函数PrewittEdgeProcess(WriteableBitmap ...
- NET C#创建WINDOWS系统用户
原文:NET C#创建WINDOWS系统用户 /前提是当前用户有相应的权限 /WinNT用户管理 using System; using System.DirectoryServices; na ...
- DEPLOYING NATIVE UWP (UNIVERSAL WINDOWS PLATFORM) APPS FOR JAVA DEVELOPERS & PUBLISHING THEM TO THE MICROSOFT STORE
原文: DEPLOYING NATIVE UWP (UNIVERSAL WINDOWS PLATFORM) APPS FOR JAVA DEVELOPERS & PUBLISHING THEM ...
- ML:吴恩达 机器学习 课程笔记(Week9~10)
Anomaly Detection Recommender Systems Large Scale Machine Learning
- Tensorflow-常见报错解决方案
1. AttributeError: 'module' object has no attribute 'SummaryWriter' tf.train.SummaryWriter 改为:tf.sum ...
- 如何解析DELPHI XE5服务器返回的JSON数据(翻译)及中文乱码
<span style="font-size:14px;">一直想找如何解析JSON数据的说,今天终于找到有人发帖子了.之前有人说用superobject,Tlkjso ...