题目链接

宽搜一下就行。

#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. 调用webapi 错误:使用 HTTP 谓词 POST 向虚拟目录发送了一个请求,而默认文档是不支持 GET 或 HEAD 以外的 HTTP 谓词的静态文件。的解决方案

    第一次调用webapi出错如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:// ...

  2. 【Python】[面向对象高级编程] 使用__slots__,使用@property

    1.使用 __slots__    给实例绑定方法, >>> def set_age(self, age): # 定义一个函数作为实例方法 ... self.age = age .. ...

  3. [转] Struts2入门示例教程

    原文地址:http://blog.csdn.net/wwwgeyang777/article/details/19078545/ 回顾Struts2的使用过程,网上搜的教程多多少少都会有点问题,重新记 ...

  4. bzoj1588

    splay #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...

  5. Sigmaplot 13 破解版什么地方可以下载

    SigmaPlot是一款专业的科学绘图软件,可用于绘制准确.高质量的图形和曲线,支持一百多种2D.3D科学图形,同时拥有强大的数据统计分析功能.现在网络不断发展,软件使用日益频繁,今天小编就和大家分享 ...

  6. Advanced Office Password Recovery如何设置快捷方式

    一般软件安装成功之后都会在桌面上形成快捷方式以方便使用,但是一些用户发现Advanced Office Password Recovery这种office密码破解工具安装成功后桌面上没有出现快捷方式, ...

  7. awk中gsub的应用

    (1)文件filename的内容 cat awk_file 1 2 3 $1,200.00 1 2 3 $2,300.00 1 2 3 $4,000.00 (2)去掉第四列的$和,并汇总第四列的和. ...

  8. 7.Android开源项目WheelView的时间和地址联动选择对话框

    类似WheelView的时间和地址联动选择对话框在现在App经常看到,今天小结下. 主布局界面: <LinearLayout xmlns:android="http://schemas ...

  9. python面向对象初级(七)

    概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向过程编程最易被初学 ...

  10. ubuntu14.04 安装pip

    参考链接: 1.http://www.liquidweb.com/kb/how-to-install-pip-on-ubuntu-14-04-lts/ 2.http://idroot.net/tuto ...