UVa 10653 - Bombs! NO they are Mines!!
题目大意:给你一个二维迷宫,给定入口和出口,找出最短路径。
无权图上的单源最短路,用BFS解决。
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define MAXN 1100 int G[MAXN][MAXN], dist[MAXN*MAXN];
const int dir[][] = {{-, }, {, -}, {, }, {, }}; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int R, C;
while (scanf("%d%d", &R, &C) && (R || C))
{
int k;
scanf("%d", &k);
memset(G, , sizeof G);
for (int i = ; i < k; i++)
{
int r, n;
scanf("%d%d", &r, &n);
for (int j = ; j < n; j++)
{
int x;
scanf("%d", &x);
G[r][x] = ;
}
}
int x, y;
scanf("%d%d", &x, &y);
int src = x*C + y;
scanf("%d%d", &x, &y);
int dest = x*C + y;
queue<int> q;
memset(dist, -, sizeof dist);
q.push(src);
dist[src] = ;
while (!q.empty())
{
int u = q.front();
q.pop();
if (u == dest) break;
int x = u / C;
int y = u % C;
for (int i = ; i < ; i++)
{
int dx = x + dir[i][], dy = y + dir[i][];
int v = dx * C + dy;
if (dx >= && dx < R && dy >= && dy < C && G[dx][dy] == && dist[v] == -)
{
dist[v] = dist[u] + ;
q.push(v);
}
}
}
printf("%d\n", dist[dest]);
}
return ;
}
UVa 10653 - Bombs! NO they are Mines!!的更多相关文章
- UVA 10653.Prince and Princess
题目 In an n * n chessboard, Prince and Princess plays a game. The squares in the chessboard are numbe ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- UVA 10765 Doves and bombs 割点
最近好懒,堆了好多题没写题解.. 原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8& ...
- UVA 10765 Doves and bombs(双连通分量)
题意:在一个无向连通图上,求任意删除一个点,余下连通块的个数. 对于一个非割顶的点,删除之后,原图仍连通,即余下连通块个数为1:对于割顶,余下连通块个数>=2. 由于是用dfs查找双连通分量,树 ...
- UVA 10765 Doves and bombs
给定一个无向的连通图,要求每个点去掉后连通分量的数目,然后输出连通分量最多的m个点. 分析: 先求出双连通分量,然后统计所有双连通分量中割顶出现的次数,最后求出的就是割顶去掉后剩下的双连通的数目,对于 ...
- Doves and bombs UVA - 10765(统计割顶所连接的连通块的数量)
题意:给定一个n个点的连通的无向图,一个点的“鸽子值”定义为将它从图中删去后连通块的个数. 求对应的点 和 每个点的“鸽子值” 用一个数组在判断割顶的那个地方 累加标记一下所连接的连通块的数量即可 初 ...
- uva 10765 Doves and Bombs(割顶)
题意:给定一个n个点的连通的无向图,一个点的"鸽子值"定义为将它从图中删去后连通块的个数.求每一个点的"鸽子值". 思路dfs检查每一个点是否为割顶,并标 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
随机推荐
- 解决phpmyadmin 点击表结构时卡顿、一直加载、打不开的问题
本文内容是转自其它站点,亲测可用. 第一步,打开 ./version_check.php文件,找到以下代码: $save = true; $file ='http://www.phpmyadmin.n ...
- HDU 1890 Robotic Sort | Splay
Robotic Sort Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [Pr ...
- elasticsearch 配置说明
elasticsearch的config文件夹里面有两个配置文件:elasticsearch.yml和logging.yml,第一个是es的基本 配置文件,第二个是日志配置文件,es也是使用log4j ...
- UESTC 1222 Sudoku
爆搜即可 /* *********************************************** author : email :523689985@qq.com created tim ...
- HaiHongOJ 1003 God Wang
题目连接:http://oj.haihongblog.com/problem.php?id=1003 线段树维护区间最小值,并且求解下标 #include <stdio.h> #inclu ...
- C# 的sql server like 的参数
//试了多种方式,这样写like的参数才正确 sb.Append(" and a.GOODSID like '%'+@GOODSID+'%'"); list.Add(new Sql ...
- php查找文件内容
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><?ph ...
- Quartz总结(三):动态修改定时器一
package com.mc.bsframe.job; import org.quartz.Scheduler; import org.quartz.SchedulerException; impor ...
- line-box(转)
inline-block是什么? Inline-block是元素display属性的一个值.这个名字的由来是因为,display设置这个值的元素,兼具行内元素( inline elements)跟块级 ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...