(2016弱校联盟十一专场10.3) B.Help the Princess!
宽搜一下就行。
#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!的更多相关文章
- 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 ...
- 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 ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
- 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> # ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search
题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...
- (2016弱校联盟十一专场10.2) E.Coins
题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...
- (2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci
题目链接 题目大意就是这个,先找出下标的循环节,再快速幂对20160519取余就行了. 找出下标循环节: #include <cstdio> #include <iostream&g ...
随机推荐
- 机器学习&数据挖掘笔记_16(常见面试之机器学习算法思想简单梳理)
前言: 找工作时(IT行业),除了常见的软件开发以外,机器学习岗位也可以当作是一个选择,不少计算机方向的研究生都会接触这个,如果你的研究方向是机器学习/数据挖掘之类,且又对其非常感兴趣的话,可以考虑考 ...
- 了解EF CodeFirst的Migrator功能与Migrator.Net对比
在上一篇[数据库迁移利器:Migrator.Net]中,很多朋友提到了EF的CodeFirst也有数据库的迁移功能,说来真惭愧,玩了那么多年,至今还未去了解EF,今天来了解下CodeFirst然后与M ...
- Codeforces Round #380(div 2)
A. 题意:给你一串字符串(<=100),将ogo ogogo ogogogo ogogogogo……这种全部缩成***,输出缩后的字符串 分析:第一遍扫对于那些go的位置,记录下next[i] ...
- Spring Boot入门===Hello World
昨天无意间看到Spring Boot ,今天又了解了一下,试着写一个Hello World! 今天看了半天,最后还是要用Maven最方便!以下: 一.工具 JDK1.7 Eclipse Maven ...
- Linux任务调度进程crontab的使用方法和注意事项
参考文章:Linux任务调度进程crond命令的使用方法和注意事项 一.crond简介 概念 crond的概念和crontab是不可分割的.crontab是一个命令,常见于Unix和类Unix的操作系 ...
- Vue.js之v-if
---恢复内容开始--- 首先,在跟着api做的时候,要把v-if包裹在Vue对应的el里面,重要的事情说三遍. html: <div id="vif"> <di ...
- 通过CAGradientLayer制作渐变色效果(转)
转载自:http://blog.it985.com/7986.html 看了极客学院的视频之后写的一篇博客,觉得不错,还是作为笔记使用. 简单介绍一下CAGradientLayer吧. Gradien ...
- 教你一招:Win10系统如何正确卸载edge浏览器?
Edge浏览器作为Win10系统默认浏览器,尽管我们将其他浏览器设置为默认程序,但是有时候还是会自动弹出,非常的不爽,但是在控制面板中却又找不到卸载“Edge”浏览器的选项.下面小编就教大家卸载“Ed ...
- Hibernate的session缓存和对象的四种状态
一.session缓存 说session缓存就得说到JAVA对象的生命周期,当没有任何引用指向一个对象时,对象则可以被gc回收,也就是生命周期结束了 而hibernate获取一个对象后,会将对象存入s ...
- session 和 cookie区别
1.存在位置cookie是储存在客服端,session是存在服务器端的文件系统/数据库/memcache 2.安全性 session是储存在服务器端,安全性高一些, 3.网络传输量 cookie通过 ...