题目链接

宽搜一下就行。

#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. 吉特仓储管系统(开源WMS)--分享两月如何做到10W+的项目

    在此文开篇之处先特别申明,此文在有些人的眼中会有广告的嫌疑,但是本人不想将其作为一个广告宣传的文章,在此提到软件内容部分请大家予以谅解和包含,作为时间不算短的程序员给大家分享一些自己开发吉特仓储管理软 ...

  2. Windows Live Writer 2012 on .net 4

    众所周知,强大的live套件不再更新,止步于2012,所以安装的时候需要.net 3.5的运行时,这很讨厌,在新系统里面是.net 4运行时的,.net运行时的设计者脑袋张虫,新的居然不默认支持旧的程 ...

  3. maven环境配置+eclipse环境配置

    一 . (1),下载maven 有点类似于tomcat 解压后就可以用 ,不用安装 (2), 配置环境变量 在系统变量的path 中添加  E:\01Server\maven\bin    注意是bi ...

  4. CentOS 6.5安装在VMWare中Bridge模式下网卡eth0不能自动激活的问题

    VMWare 12.5.2 CentOS 6.5 basic VMWare网卡配置选择Bridge方式 问题: 默认情况下ifconfig命令只能看到网络设备lo,看不到eth0,也没有分配合理的IP ...

  5. Sokcet方式请求HTTP/HTTPS的封装类HttpHelper

    using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; ...

  6. Delphi dll 断点调试

    1.dll 要有一个依托的exe(怎么做 相信用dll了一定知道) 2.选项中的compling中的debugging中的选项,linking中的所有选项 3.最后一个也就是最重要的 run中的par ...

  7. 【USACO 2.4】Fractions to Decimals(分数转小数)

    题意:给你N/D的分数,让你输出等价的小数,如果是循环小数,用括号把循环节包起来.如果是整数,后面保留一位小数.每行最多输出76个字符. 题解:模拟除法,如果余数是第二次出现,则代表第一次出现的位置到 ...

  8. Python笔记(1)变量与表达式

    列表list list是用的最多的类型 可以count计数 可嵌套,多钟类型并存 支持 + * a = [1,2,3] a_ref = a a_copy = a[:] 引用,a变化a_ref也变化 指 ...

  9. UIText光标用法

    1.获取当前光标位置 UITextRange *range = _textField.selectedTextRange; 2.选取开始到最后的文字 UITextPosition *start = [ ...

  10. Ubuntu学习总结-07 Nodejs和npm的安装

    一 安装NodeJS 1 下载nodejs源码 从以下网址下载最新的Nodejs源码 https://nodejs.org/en/download/ 2 安装依赖的 python,gcc,g++ 函数 ...