LightOJ 1238 Power Puff Girls(BFS)
来源:互联网 发布:翟欣欣最新进展 知乎 编辑:程序博客网 时间:2024/05/20 03:40
题解;
对a,b,c三个点各求一次bfs然后取最大值即可
代码
#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>using namespace std;#define maxn 100000#define LL long longint cas=1,T;int n,m;char mapp[25][25];int visit[25][25];int dx[] = {0,0,1,-1};int dy[] = {1,-1,0,0};struct Node{ int x,y; int step;};bool check(int x,int y){ if (x<0 || y<0 || x>=n || y>=m) return true; if (visit[x][y] || mapp[x][y]=='#' || mapp[x][y]=='m' ) return true; return false;}int bfs(Node s){ visit[s.x][s.y]=1; queue<Node> q; q.push(s); while (!q.empty()) { Node t = q.front(); q.pop(); if (mapp[t.x][t.y]=='h') return t.step; for (int i = 0;i<4;i++) { Node temp; temp.x = t.x+dx[i]; temp.y = t.y+dy[i]; if (check(temp.x,temp.y)) continue; visit[temp.x][temp.y]=1; temp.step = t.step+1; q.push(temp); } } //memset(visit,0,sizeof(visit));}int main(){ scanf("%d",&T); while (T--) { printf("Case %d: ",cas++); Node a,b,c; scanf("%d%d",&n,&m); for (int i = 0;i<n;i++) scanf("%s",&mapp[i]); int atime,btime,ctime; for (int i = 0;i<n;i++) for (int j = 0;j<m;j++) { if (mapp[i][j]=='a') { a.x=i; a.y=j; a.step=0; atime = bfs(a); memset(visit,0,sizeof(visit)); } if (mapp[i][j]=='b') { b.x=i; b.y=j; b.step=0; btime = bfs(b); memset(visit,0,sizeof(visit)); } if (mapp[i][j]=='c') { c.x=i; c.y=j; c.step=0; ctime = bfs(c); memset(visit,0,sizeof(visit)); } } int mins =0; mins = max(atime,max(btime,ctime)); printf("%d\n",mins); memset(mapp,0,sizeof(mapp)); memset(visit,0,sizeof(visit)); } //freopen("in","r",stdin); //scanf("%d",&T); //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); return 0;}
0 0
- LightOJ 1238 Power Puff Girls(BFS)
- Lightoj1238——Power Puff Girls(bfs)
- Light OJ 1238 - Power Puff Girls
- LightOJ 1175 (BFS)
- lightoj--1155--Power Transmission(最大流拆点)
- Lightoj 1066 Gathering Food(BFS)
- 【LightOJ】1122 - Digit Count(bfs)
- hdu 2579 Dating with girls(2)(BFS)
- hdu 2579 Dating with girls(2) (BFS)
- HDU 2579 Dating with girls(2) (bfs)
- HDOJ 2579 Dating with girls(2) (BFS)
- 【HDU】 2579 Dating with girls(2)(BFS,可重复)
- HDU_2579_Dating with girls(2) (BFS)
- hdoj2579Dating with girls(2)【BFS】
- Lightoj 1141 BFS
- Lightoj 1009 BFS
- LightOJ 1174--Commandos (BFS)
- LightOJ-1046-BFS
- JVM中的类加载原理
- 为app提供api,架构该怎么设计,需要考虑高并发,访问量比较大
- 获取相册相机,定位
- 最新Google Gmail邮箱登陆不了解决方法
- android蓝牙遥控车
- LightOJ 1238 Power Puff Girls(BFS)
- 图像特征
- C#链接文件的应用
- 在Ubuntu上下载Android最新源代码
- Android下微信、微博、qq、百度第三方登陆
- java导出excel表
- 使用Pyunit执行测试并生成HTML报告
- Android 平台语言对照表
- mac配置adb