http://acm.zznu.edu.cn/problem.php?id=1967

这套题的有毒   我交了好多遍才对

坑:机关要按照顺序走 并且在走这个机关之前不能走这个机关  但是能穿过这个机关   所以不能把机关刚开始设成墙

要设成其他符号

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath> using namespace std;
#define memset(a,b) memset(a,b,sizeof(a))
#define N 110 struct node
{
int x,y,step;
}e[N]; char maps[N][N];
int n,m;
int dis[][]={{,},{-,},{,},{,-},{-,-},{,},{-,},{,-}};
int vis[N][N]; int IF(int x,int y,int nx,int ny,int k)
{
if(maps[x][y]=='*' || maps[x][y]=='#' || x< || x>=n || y< || y>=m || vis[x][y]==)
return ;
if(k>=)
{
if(k==)
{
if(maps[x][y+]=='#'&&maps[x+][y]=='#')
return ;
}
if(k==)
{
if(maps[x][y-]=='#' && maps[x-][y]=='#')
return ;
}
if(k==)
{
if(maps[x][y-]=='#' && maps[x+][y]=='#')
return ;
}
if(k==)
{
if(maps[x][y+]=='#' && maps[x-][y]=='#')
return ;
}
}
return ;
} int bfs(node s,node o)
{
memset(vis,);
queue <node>Q;
Q.push(s);
vis[s.x][s.y]=;
while(Q.size())
{
node p,q;
p=Q.front();
Q.pop();
if(p.x==o.x && p.y==o.y)
return p.step;
for(int i=;i<=;i++)
{
q.x=p.x+dis[i][];
q.y=p.y+dis[i][];
if(IF(q.x,q.y,p.x,p.y,i)==)
{
q.step=p.step+;
Q.push(q);
vis[q.x][q.y]=;
}
}
}
return -;
} int main()
{
int T,k;
scanf("%d",&T);
while(T--)
{
int flag=;
scanf("%d %d %d",&n,&m,&k);
for(int i=;i<n;i++)
{
scanf("%s",maps[i]);
}
for(int i=;i<=k;i++)
{
scanf("%d %d",&e[i].x,&e[i].y);
e[i].step=;
if(i!= && i!=)
{
if(e[i].x==e[].x && e[i].y==e[].y)
flag=;
}
}
if(flag==)
{
printf("-1\n");
continue;
}
int ans=,sum=;;
for(int i=;i<=k;i++)
{
for(int j=i+;j<=k;j++)
{
maps[e[j].x-][e[j].y-]='*';
}
node S,E;
S.x=e[i-].x-;
S.y=e[i-].y-;
S.step=;
E.x=e[i].x-;
E.y=e[i].y-;
E.step=;
ans=bfs(S,E);
if(ans==-)
{
sum=-;
break;
}
else
sum+=ans;
for(int j=i+;j<=k;j++)
{
maps[e[j].x-][e[j].y-]='.';
}
}
printf("%d\n",sum);
}
return ;
}

2015轻院校赛 B 迷宫 (bfs)的更多相关文章

  1. 2015轻院校赛 D 社交网络(排列组合)

    http://acm.zznu.edu.cn/problem.php?id=1964 题目描述 输入 输出 样例输入 2 2 1 0 1 1 0 3 1 0 1 1 1 0 1 1 1 0 样例输出 ...

  2. 2015北京网络赛 G Boxes BFS+打表

    G Boxes 题意:n个位置摆有n个箱子,每次移动只能把相邻的垒起来,且上面的必须小于下面的.求摆成升序需要移动多少步. 思路:这里的n很小,只有7.但是bfs最快的情况需要2s左右,所以就打表了. ...

  3. 【DFS+堆的二叉树结构】15轻院校赛-J-堆

    [题目链接:J-堆] 1734: 堆 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 239  Solved: 113 SubmitStatusWeb B ...

  4. 【二叉树、堆】15轻院校赛-J-堆

    原题:http://acm.zzuli.edu.cn/problem.php?cid=1099&pid=9 [描述] [输入] [输出] Sample Input 3 1 10 3 10 5 ...

  5. 轻院校赛-zzuli 2266: number【用每位的二进制的幂的和来进行hash(映射)处理】

    zzuli 2266: number 大致题意:   给定n,问有多少数对<x, y>满足: x, y∈[1, n], x < y            x, y中出现的[0, 9] ...

  6. ZOJ 1649 Rescue(有敌人迷宫BFS)

    题意 求迷宫中从a的位置到r的位置须要的最少时间  经过'.'方格须要1s  经过'x'方格须要两秒  '#'表示墙 因为有1s和2s两种情况  须要在基础迷宫bfs上加些推断 令到达每一个点的时间初 ...

  7. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...

  8. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

  9. 2015北京网络赛 Couple Trees 倍增算法

    2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道.  解法来自 q ...

随机推荐

  1. mongodb多条件查询总结

    根据两字段乘积过滤查询分页数据 db.cron.aggregate([{$project:{_id:,AppID:,result:{$add:["$endlottery",&quo ...

  2. [Github筆記] 清除所有 Commit 紀錄

    # 把原來的 git 移除掉 sudo rm .git -r # 初始化 git init git remote add origin https://github.com/username/repo ...

  3. systemtap执行过程中报probe timer.profile registration error

    probe timer.profile registration error 今天在执行火焰图的过程中,代码报错,probe timer.profile registration error 经过查询 ...

  4. Linux-RedHat7.2 安装nginx托管.net core2.0

    1.安装依赖包 yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel 2.下载安装包 wge ...

  5. 阿里云人脸比对API封装

    这是根据封装是根据阿里云官方给的Demo进行修改的,当时是因为编写微信小程序云函数需要使用到阿里云人脸比对接口,才对其进行封装的. 记录下来,方便下次使用. 复制下来可以直接使用. 用到的依赖如下: ...

  6. ES6 第五章 字符串的新增方法 具体参照 http://es6.ruanyifeng.com

    1.FormCodePoint 对象方法 用于从 Unicode 码点返回对应字符,可以识别原来es5不能识别的大于0xFFFF的码点. String.fromCodePoint(0x20BB7) / ...

  7. java中HashMap,LinkedHashMap,TreeMap,HashTable的区别

    java为数据结构中的映射定义了一个接口java.util.Map;它有四个实现类,分别是HashMap Hashtable LinkedHashMap 和TreeMap Map主要用于存储健值对,根 ...

  8. RTSP详解

    关于 RTSP. RTSP协议是一个非常类似HTTP协议的流控制协议.它们都使用纯文本来发送信息,而且rtsp协议的语法也和HTTP类似.Rtsp一开始这样设计,也是为了能够兼容使用以前写的HTTP协 ...

  9. 点击增加删除class

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. 牛客网练习赛25 C 再编号

    链接:https://www.nowcoder.com/acm/contest/158/C来源:牛客网 定义对 a 的再编号为 a' ,满足 . 现在有 m 次询问,每次给定 x,t ,表示询问经过 ...