Fire Game

题意:

两个小朋友可以任选一块草地点火,草地可以不同,也可以相同,问最少的烧光草地的时间。

思路:

一开始看到这个以为是联通块计数,没想到这道题通过枚举两个起始点作为队列的初始点,每次跑一边bfs即可。

  1. #include <algorithm>
  2. #include <iterator>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <iomanip>
  7. #include <bitset>
  8. #include <cctype>
  9. #include <cstdio>
  10. #include <string>
  11. #include <vector>
  12. #include <cmath>
  13. #include <queue>
  14. #include <list>
  15. #include <map>
  16. #include <set>
  17. using namespace std;
  18. //#pragma GCC optimize(3)
  19. //#pragma comment(linker, "/STACK:102400000,102400000") //c++
  20. #define lson (l , mid , rt << 1)
  21. #define rson (mid + 1 , r , rt << 1 | 1)
  22. #define debug(x) cerr << #x << " = " << x << "\n";
  23. #define pb push_back
  24. #define pq priority_queue
  25.  
  26. typedef long long ll;
  27. typedef unsigned long long ull;
  28.  
  29. typedef pair<ll ,ll > pll;
  30. typedef pair<int ,int > pii;
  31. typedef pair<int,pii> p3;
  32.  
  33. //priority_queue<int> q;//这是一个大根堆q
  34. //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
  35. #define fi first
  36. #define se second
  37. //#define endl '\n'
  38.  
  39. #define OKC ios::sync_with_stdio(false);cin.tie(0)
  40. #define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
  41. #define REP(i , j , k) for(int i = j ; i < k ; ++i)
  42. //priority_queue<int ,vector<int>, greater<int> >que;
  43.  
  44. const ll mos = 0x7FFFFFFFLL; //
  45. const ll nmos = 0x80000000LL; //-2147483648
  46. const int inf = 0x3f3f3f3f;
  47. const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
  48. const int mod = 1e9+;
  49.  
  50. const double PI=acos(-1.0);
  51.  
  52. // #define _DEBUG; //*//
  53. #ifdef _DEBUG
  54. freopen("input", "r", stdin);
  55. // freopen("output.txt", "w", stdout);
  56. #endif
  57. /*-----------------------showtime----------------------*/
  58. const int maxn = ;
  59. int n,m;
  60. string mp[maxn];
  61. int dp[maxn][maxn];
  62.  
  63. int nt[][] = {
  64. {,},{,},{-,},{,-},
  65. };
  66. struct node
  67. {
  68. int x,y,step;
  69. }q[maxn*maxn];
  70. int mx,tot;
  71. void bfs(node a,node b){
  72. mx = ;
  73. for(int i=; i<maxn; i++){
  74. for(int j=; j<maxn; j++)dp[i][j] = inf;
  75. }
  76. queue<node>que;
  77. que.push(a);
  78. if(a.x!=b.x||a.y!=b.y)que.push(b);
  79. dp[a.x][a.y] = ;
  80. dp[b.x][b.y] = ;
  81. while(!que.empty()){
  82. int x = que.front().x,y = que.front().y,s = que.front().step;
  83. que.pop();
  84. for(int i= ; i<; i++){
  85. int nx = x + nt[i][],ny = y + nt[i][];
  86. if(nx < ||nx >=n || ny <||ny>=m)continue;
  87. if(mp[nx][ny]=='.')continue;
  88. if(dp[nx][ny] > s + ){
  89. dp[nx][ny] = s + ;
  90. mx = max(mx,s+);
  91. node tmp={nx,ny,s+};
  92. que.push(tmp);
  93.  
  94. }
  95. }
  96. }
  97. }
  98. void solve(){
  99. cin>>n>>m;
  100.  
  101. for(int i=; i<n; i++){
  102. cin>>mp[i];
  103. }
  104. int cnt = ,ans = inf;
  105. for(int i=; i<n ; i++){
  106. for(int j=; j<m; j++){
  107. if(mp[i][j]=='#'){
  108. q[++cnt].x = i;
  109. q[cnt].y = j;
  110. q[cnt].step = ;
  111. }
  112. }
  113. }
  114.  
  115. for(int i=; i<=cnt; i++)
  116. {
  117.  
  118. for(int j=i; j<=cnt; j++){
  119. bfs(q[i],q[j]);
  120. int flag = ;
  121. for(int x = ; x < n; x++){
  122. for(int y = ; y<m; y++){
  123. if(dp[x][y] >=inf && mp[x][y] == '#')flag= ;
  124. }
  125. }
  126. if(flag)ans = min(ans, mx);
  127.  
  128. }
  129. }
  130. if(ans < inf)cout<<ans<<endl;
  131. else cout<<-<<endl;
  132. }
  133. int main(){
  134. int T; cin>>T;
  135. for(int t=;t<=T;t++){
  136. cout<<"Case "<<t<<": ";
  137. solve();
  138. }
  139. return ;
  140. }

FZU-2150

FZU - 2150-Fire Game BFS-枚举的更多相关文章

  1. FZU - 2150 Fire Game bfs+双起点枚举

    题意,10*10的地图,有若干块草地“#”,草地可以点燃,并在一秒后点燃相邻的草地.有墙壁‘·‘阻挡.初始可以从任意两点点火.问烧完最短的时间.若烧不完输出-1. 题解:由于100的数据量,直接暴力. ...

  2. (FZU 2150) Fire Game (bfs)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...

  3. FZU 2150 Fire Game (bfs+dfs)

    Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...

  4. FZU 2150 Fire Game(点火游戏)

    FZU 2150 Fire Game(点火游戏) Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description - 题目描述 ...

  5. fzu 2150 Fire Game 【身手BFS】

    称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...

  6. FZU 2150 Fire Game (暴力BFS)

    [题目链接]click here~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...

  7. FZU 2150 fire game (bfs)

    Problem 2150 Fire Game Accept: 2133    Submit: 7494Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  8. FZU 2150 Fire Game

    Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  9. 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) ...

  10. FZU 2150 Fire Game(BFS)

    点我看题目 题意 :就是有两个熊孩子要把一个正方形上的草都给烧掉,他俩同时放火烧,烧第一块的时候是不花时间的,每一块着火的都可以在下一秒烧向上下左右四块#代表草地,.代表着不能烧的.问你最少花多少时间 ...

随机推荐

  1. Java 之MVC动态分页完美实现

    一个分页小技术有时也是让人挠头,在这里完全前端实现方式与Java的实现方式,我们提供给你完全的编码参考,希望能够帮到你哦(:) 内容导读 1.程序结构 2.JSP页面设计 3.分页主要编码 4.运行效 ...

  2. 放出一批学生管理系统jsp源码,部分有框架

    基于jsp+struts 2的学生管理系统eclipse - 源码码头   https://www.icodedock.com/article/25.html 基于jsp+mysql的JSP学生成绩管 ...

  3. LR有的JMeter也有之二“检查点”

    好吧!接着上一篇文章的内容和思路,继续前进. 检查点:简单的来理解一下,上一章讲到,我们对用户名和密码进行了参数化,那么怎样来判断jmeter有没有正确调用test.dat里面的文件呢.当然,我们可以 ...

  4. Spring Cloud 之 Stream.

    一.简介 Spring Cloud Stream 是一个用来为微服务应用构建消息驱动能力的框架. Spring Cloud Stream 为一些供应商的消息中间件产品(目前集成了 RabbitMQ 和 ...

  5. NLP(十四)自制序列标注平台

    背景介绍   在平时的NLP任务中,我们经常用到命名实体识别(NER),常用的识别实体类型为人名.地名.组织机构名,但是我们往往也会有识别其它实体的需求,比如时间.品牌名等.在利用算法做实体识别的时候 ...

  6. 洛谷 P2024 [NOI2001]食物链

    题意简述 有人用两种说法对这 N 个动物所构成的食物链关系进行描述: 1."1 X Y",表示 X 和 Y 是同类. 2."2 X Y",表示 X 吃 Y . ...

  7. python骚操作---Print函数用法

    ---恢复内容开始--- python骚操作---Print函数用法 在 Python 中,print 可以打印所有变量数据,包括自定义类型. 在 3.x 中是个内置函数,并且拥有更丰富的功能. 参数 ...

  8. Spring boot中的 JsonConverter

    上图是spring-web包的部分目录 为了找出调用了哪种类型的Convert 我找到父类 HttpMessageConverter 查看了它的引用 在spring-boot-autoconfigur ...

  9. 关于阿里云Mysql分页查询不走索引的问题

    需要修改阿里云中的MYSQL 配置参数 : eq_range_index_dive_limit 阿里云上默认是 10 , 这个参数 表示 in 查询 条件超过 10 个 就不走索引,走全表扫描.如果我 ...

  10. div css float布局用法

    float的应用与用法 想要知道float的用法,首先你要知道float在网页中的用处. 浮动的目的就是为了使得设置的对象脱离标准文档流. 什么是标准文档流? 网页在解析的时候,遵循于从上向下,从左向 ...