FZU Problem 2028 时空门问题
Problem Description
Input
Output
Sample Input
Sample Output
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define N 505
#define M 505
int n,m,step,si,sj,ti,tj,dir[][]={{,},{-,},{,},{,-}};
char map[N][M];
bool flag[N][M];
struct point{
int x,y;
point (int x,int y):x(x),y(y){}
};
vector<point>v[N][M];//把vector容器变为数组型的容器,方便数据的存储,
struct node
{
int x,y,t;
node(int x,int y,int t):x(x),y(y),t(t){}
node(){}
};
queue<node>q;
void bfs()
{
while(!q.empty())
q.pop();
q.push(node(si,sj,));
map[si][sj]='#';
int x,y,t;
node n1;
while(!q.empty())
{
n1=q.front();q.pop();
for(int i=;i<;i++)//常规的四个方向的寻找
{
x=n1.x+dir[i][];
y=n1.y+dir[i][];
if(map[x][y]!='#')
{
t=n1.t+;
map[x][y]='#';
if(x==ti && y==tj)
{
step=t;
return ;
}
q.push(node (x,y,t));
}
}
int len=v[n1.x][n1.y].size();
for(int i=;i<len;i++)//取出满足条件的点,进行穿梭,然后再进行存储;
{
x=v[n1.x][n1.y][i].x;
y=v[n1.x][n1.y][i].y;
if(map[x][y]!='#')
{
t=n1.t+;
map[x][y]='#';
if(x==ti && y==tj)
{
step=t;
return ;
}
q.push(node (x,y,t));
}
}
}
}
int main()
{
int i,j;
while(cin>>n>>m)
{
memset(map,'#',sizeof(map));
getchar();
for( i = ; i <= n; ++i )
{
gets(map[i]+);
for( j = ; j <= m; ++j )
{
v[i][j].clear();
if( map[i][j] == 's' ) si = i, sj = j;
else if( map[i][j] == 't' ) ti = i, tj = j;
}
}
int k,xx,yy;
for( i = ; i <= n; ++i )
{
for( j = ; j <= m; ++j )
{
scanf("%d", &k);
while(k--)
{
scanf("%d%d", &xx, &yy);
v[i][j].push_back(point(xx,yy));//这个二维的容器很好用,我也是刚学会的
}
}
}
bfs();
cout<<step<<endl;
}
return ;
}
FZU Problem 2028 时空门问题的更多相关文章
- FZU Problem 2028 时空门问题(DFS+优化)
一开始是MLE,后来想到了用vector,化二维为一维,做了这一步优化后,这就是很基础的一个广搜了 #include<iostream> #include<cstdio> #i ...
- FZu Problem 2233 ~APTX4869 (并查集 + sort)
题目链接: FZu Problem 2233 ~APTX4869 题目描述: 给一个n*n的矩阵,(i, j)表示第 i 种材料 和 第 j 种材料的影响值,这个矩阵代表这n个物品之间的影响值.当把这 ...
- FZu Problem 2236 第十四个目标 (线段树 + dp)
题目链接: FZu Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...
- 翻翻棋(找规律问题)(FZU Problem 2230)
题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...
- FZU 2028 时空门问题
题目链接:时空门问题 简单bfs,每个格子移动的方式除了上下左右,还有时空门,开始想着用邻接表保存每个点能通过时空门到达的点就ok了.很快的敲出来,很快的WA了.长久的dbug并没有发现error.然 ...
- fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)
题目:http://acm.fzu.edu.cn/problem.php?pid=2148 题意:给出n个点,判断可以组成多少个凸四边形. 思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是 ...
- fzu Problem 2140 Forever 0.5(推理构造)
题目:http://acm.fzu.edu.cn/problem.php?pid=2140 题意: 题目大意:给出n,要求找出n个点,满足: 1)任意两点间的距离不超过1: 2)每个点与(0,0)点的 ...
- Fzu Problem 2082 过路费 LCT,动态树
题目:http://acm.fzu.edu.cn/problem.php?pid=2082 Problem 2082 过路费 Accept: 528 Submit: 1654Time Limit ...
- FZU Problem 2169 shadow
http://acm.fzu.edu.cn/problem.php?pid=2169 题目大意: S王国有N个城市,有N-1条道路.王都为编号1的城市.叛军驻扎在很多城市.除了王都外有K个城市有军队, ...
随机推荐
- Ubuntu下安装zookeeper
1:下载安装文件 zookeeper-3.4.9.tar.gz 2:解压到以下目录 /usr/local/services/zookeeper/zookeeper-3.4.9 3:进入conf目录,复 ...
- OpenERP在product中增加外部网络链接图片
最近的一个项目要求在Product_Template中增加类似与HTML中<img src=”" />的形式的图片 product_img_extra.py from osv i ...
- eclipse c++ 经常使用快捷键
atl+/ //自己主动补全 ctrl+/ //凝视,或者去凝视 ctrl+shift+F //代码整理 ctrl+shift+G //跳转到调用的地方,或者,右键+Reference+Project ...
- java 中文转拼音之pinyin4j
一.简介 有时候,须要将汉字编程相应的拼音.以方便数据的处理.比方在Android手机应用的开发上.要查询联系人的姓名.通常都是用拼音进行查询的. 比方要查询"曹孟德",就能够输入 ...
- python之函数用法bin()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法bin() #bin() #说明:一个整数转换为一个二进制字符串 ''' bin(.. ...
- JMeter入门:Java Request实例 (转)
转自:http://blog.csdn.net/czp11210/article/details/26174969 目的:对Java程序进行测试: 一.核心步骤 1.创建一个Java工程: 2 ...
- Oracle执行SQL报错ORA-00922
问题描述: 对Oracle数据库执行序列化脚本出错,ora-00922 missing or invalid option #无效的选项 问题解决: 对于set define off --这个是sq ...
- 微信小程序独家秘笈之抽奖大转盘
代码地址如下:http://www.demodashi.com/demo/14209.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- Spring MVC Beginner’s Guide勘误表
- 17 submitted: last submission 09 Dec 2016 Page number: 213 Qauntity should be: Quantity Page numbe ...
- 【LeetCode】154. Find Minimum in Rotated Sorted Array II (3 solutions)
Find Minimum in Rotated Sorted Array II Follow up for "Find Minimum in Rotated Sorted Array&quo ...