题意:

就是公主要逃跑,士兵要抓公主,问你能不能逃跑哇;

思路:

就是终点搞成起点,然后BFS一下就好了,最后枚举一下出口到公主的距离是不是<所有的到士兵的距离;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; const int N=2e2+10; struct asd{
int x,y;
};
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
char s[N][N];
int step[N][N];
int n,m;
int sx,sy;
queue<asd>q; void init()
{
while(!q.empty())
q.pop();
memset(step,-1,sizeof(step));
} bool Judge(int x,int y)
{
if(x<0||y<0||x>=n||y>=m)
return 0;
if(s[x][y]=='#')
return 0;
return 1;
} void bfs()
{
init();
asd now,next;
now.x=sx;
now.y=sy;
step[now.x][now.y]=0;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
// printf("%d %d\n",now.x,now.y);
for(int i=0;i<4;i++)
{
int x=now.x+dx[i];
int y=now.y+dy[i];
if(Judge(x,y))
{
if(step[x][y]==-1)
{
step[x][y]=step[now.x][now.y]+1;
next.x=x;
next.y=y;
q.push(next);
}
}
}
}
int temp1;
int temp2=0x3f3f3f3f;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='@')
{
temp1=step[i][j];
}
if(s[i][j]=='$'&&step[i][j]!=-1)
{
temp2=min(temp2,step[i][j]);
}
}
}
if(temp1<temp2)
puts("Yes");
else
puts("No");
} int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",s[i]);
int f=0; for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='%')
{
sx=i;
sy=j;
f=1;
break;
}
}
if(f)
break;
}
bfs();
return 0;
}

JAG Practice Contest for ACM-ICPC Asia Regional 2016B题【BFS】的更多相关文章

  1. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  2. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  3. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  4. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  5. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  6. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  7. hduoj 4706 Children&#39;s Day 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...

  8. 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

    hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  10. 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. jquery ui 怎么实现tab标签切换效果

    1.效果图 2.HTML 代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...

  2. Page (computer memory)

    A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described ...

  3. 20170316 REUSE_alv_display_lvc 面向对象函数

    **将ALV显示数据更新进输出内表中  DATA: LR_GRID TYPE  REF TO CL_GUI_ALV_GRID.  CALL FUNCTION 'GET_GLOBALS_FROM_SLV ...

  4. UIAutomator 2

    UIAutomator 2 While the API remains almost the same, the internal implementation has changed and we ...

  5. ORA-02298: 无法验证 (PNET.POST_CLOB_FK) - 未找到父项关键字

    在运行以下语句的时候,报错如下: ALTER TABLE PN_POST ADD CONSTRAINT POST_CLOB_FK FOREIGN KEY (POST_BODY_ID) REFERENC ...

  6. vue 仿今日头条

    vue 仿今日头条 为了增加移动端项目的经验,近一周通过 vue 仿写今日头条,以下就项目实现过程中遇到的问题以及解决方法给出总结,有什么不正确的地方,恳请大家批评指正^ _ ^!,代码仓库地址为 g ...

  7. 编辑xml文件时不能自动提示问题的解决

    在编辑xml文件时,eclipse总是不能自动提示,在网上找了一些资料,大部分都是说关于xml editor配置的,下面也把这个方法罗列在下面,以供参考: 解决办法:在eclipse的菜单里,找到wi ...

  8. the art of seo(chapter six)

    Developing an SEO-Friendly Website ***Making Your Site Accessible to Search Engines***1.Indexable Co ...

  9. git比较两个版本,获取所有代码有差别的文件,并拷贝到一个文件夹中

    git diff 3b3855d a024af5 --name-only | xargs -i cp '{}' ./update/ --parents 解释:通过xargs 命令,把git diff  ...

  10. input处理函数

    input处理函数是潜在的影响你app性能的问题,他们可以阻止帧的形成,并且可以造成多余的亦或不必要的layout的工作. 避免长时间运行input handler:它们会阻塞scroll 不要在in ...