题目链接

宽搜一下就行。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,m;
char str[][];
int to[][]={,,-,,,,,-};
bool mp[][];
bool check(int x,int y)
{
if(x<||x>=n||y<||y>=m)return ;
if(str[x][y]=='#'||mp[x][y]==)return ;
return ;
}
int prx,pry;
struct node
{
int x,y,time;
}; bool bfs(int posx,int posy)
{
int pt=-,st=-;
queue<node>Q;
node a,next;
mp[posx][posy]=;
a.x=posx,a.y=posy,a.time=;
Q.push(a);
while(!Q.empty())
{
a=Q.front();
Q.pop();
if(st==-&&str[a.x][a.y]=='$') {
st = a.time+;
}
if(str[a.x][a.y]=='@'&&pt==-) {
pt = a.time+;
}
if(pt!=-&&st!=-) {
if(pt>=st) return ;
else return ;
}
for(int i=;i<;i++)
{
next=a;
next.x+=to[i][];
next.y+=to[i][];
if(check(next.x,next.y))continue;
next.time=a.time+;
mp[next.x][next.y]=;
Q.push(next);
}
}
if(pt!=-)
return ;
else return ;
}
int main()
{
// freopen("cin.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
int posx,posy;
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
{
scanf("%s",str[i]);
for(int j=;j<m;j++)
if(str[i][j]=='%')
{
posx=i;
posy=j;
}
}
if(bfs(posx,posy))puts("Yes");
else puts("No");
}
return ;
}

(2016弱校联盟十一专场10.3) B.Help the Princess!的更多相关文章

  1. 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)

    题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8506#problem/A problem description As we know, t ...

  2. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  3. (2016弱校联盟十一专场10.3) D Parentheses

    题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...

  4. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

  5. 2016弱校联盟十一专场10.3---We don't wanna work!(STL--set的使用)

    题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8504#problem/C 代码如下: #include <iostream> # ...

  6. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  7. (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search

    题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...

  8. (2016弱校联盟十一专场10.2) E.Coins

    题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...

  9. (2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci

    题目链接 题目大意就是这个,先找出下标的循环节,再快速幂对20160519取余就行了. 找出下标循环节: #include <cstdio> #include <iostream&g ...

随机推荐

  1. JS组件系列——Bootstrap Table 表格行拖拽(二:多行拖拽)

    前言:前天刚写了篇JS组件系列——Bootstrap Table 表格行拖拽,今天接到新的需要,需要在之前表格行拖拽的基础上能够同时拖拽选中的多行.博主用了半天时间研究了下,效果是出来了,但是感觉不尽 ...

  2. JS组件系列——分享自己封装的Bootstrap树形组件:jqTree

    前言:之前的一篇介绍了下如何封装自己的组件,这篇再次来体验下自己封装组件的乐趣.看过博主博客的园友应该记得之前分享过一篇树形菜单的使用JS组件系列——Bootstrap 树控件使用经验分享,这篇里面第 ...

  3. Java使用代理服务器

    HTTP协议是基于TCP协议的,TCP协议在Java中的体现就是套接字.在了解HTTP协议的基础上,完全可以通过TCP来实现一套HTTP库,这个库可以发起网络请求和接受网络请求.只要能用URLConn ...

  4. python爬某个网站的图片

    # _*_ coding: gbk _*_ import urllib import urllib2 import re class Spider: def getImage(self,html): ...

  5. Python终端如何输出彩色字体

    实现过程:       终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关.       转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示是27 ...

  6. strlen()和sizeof()求数组长度

    在字符常量和字符串常量的博文里有提: 求字符串数组的长度 标准库函数strlen(s)可以返回字符串s的长度,在头文件<string.h>里. strlen(s)的判断长度的依据是(s[i ...

  7. 【原】理解javascript中的闭包

    闭包在javascript来说是比较重要的概念,平时工作中也是用的比较多的一项技术.下来对其进行一个小小的总结 什么是闭包? 官方说法: 闭包是指有权访问另一个函数作用域中的变量的函数.创建闭包的常见 ...

  8. IBatis 批量插入数据之SqlBulkCopy

    public void AddLetters(IList<int> customerIds, string title, string content, LetterEnum.Letter ...

  9. .NET学习之路----我对P/Invoke技术的理解(一)

    看了P/Invoke技术的介绍,于是想写下点东西,东西包含两个部分:知识的纪录和我的理解及疑问. r托管代码中调用非托管API函数的过程 1.定位包含API的DLL: 2.载入DLL 3.找到DLL中 ...

  10. epoll ET模式陷阱分析

    0. 前言 这篇文章主要记录在使用epoll实现NIO接入时所遇到的问题. 1. epoll简介 epoll是Linux下提供的NIO,其主要有两种模式,ET(Edge trige)和LT(Level ...