BZOJ1671: [Usaco2005 Dec]Knights of Ni
1671: [Usaco2005 Dec]Knights of Ni
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 175 Solved: 107
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
4 1 0 0 0 0 1 0
0 0 0 1 0 1 0 0
0 2 1 1 3 0 4 0
0 0 0 4 1 1 1 0
INPUT DETAILS:
Width=8, height=4. Bessie starts on the third row, only a few squares away
from the Knights.
Sample Output
OUTPUT DETAILS:
Bessie can move in this pattern to get a shrubbery for the Knights:
N, W, N, S, E, E, N, E, E, S, S. She gets the shrubbery in the northwest
corner and then makes her away around the barriers to the east and then
south to the Knights.
HINT
Source
- #include<cstdio>
- #include<cstring>
- struct target{
- int x,y;
- }t[];
- struct queue{
- int x,y;
- }q[];
- const int mx[]={,,,-};
- const int my[]={,,-,};
- int n,m,cnt,x1,y1,x2,y2,head,tail,ans=;
- int map[][];
- int dis1[][];
- int dis2[][];
- bool mrk[][];
- inline int min(int a,int b)
- {return a<b?a:b;}
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- inline void bfs1(int x,int y)
- {
- head=;tail=;mrk[x][y]=;
- q[].x=x;q[].y=y;
- while (head<tail)
- {
- int nx=q[++head].x,ny=q[head].y;
- for (int k=;k<;k++)
- {
- int xx=nx+mx[k],yy=ny+my[k];
- if (xx<||xx>n||yy<||yy>m)continue;
- if (mrk[xx][yy]||map[xx][yy]==) continue;
- dis1[xx][yy]=dis1[nx][ny]+;
- q[++tail].x=xx;q[tail].y=yy;
- mrk[xx][yy]=;
- }
- }
- }
- inline void bfs2(int x,int y)
- {
- memset(q,,sizeof(q));
- memset(mrk,,sizeof(mrk));
- head=;tail=;mrk[x][y]=;
- q[].x=x;q[].y=y;
- while (head<tail)
- {
- int nx=q[++head].x,ny=q[head].y;
- for (int k=;k<;k++)
- {
- int xx=nx+mx[k],yy=ny+my[k];
- if (xx<||xx>n||yy<||yy>m)continue;
- if (mrk[xx][yy]||map[xx][yy]==) continue;
- dis2[xx][yy]=dis2[nx][ny]+;
- q[++tail].x=xx;q[tail].y=yy;
- mrk[xx][yy]=;
- }
- }
- }
- int main()
- {
- m=read();n=read();
- for (int i=;i<=n;i++)
- for(int j=;j<=m;j++)
- {
- map[i][j]=read();
- if (map[i][j]==)
- {
- t[++cnt].x=i;
- t[cnt].y=j;
- }else
- if (map[i][j]==)
- {
- x1=i;
- y1=j;
- map[i][j]=;
- }else
- if (map[i][j]==)
- {
- x2=i;
- y2=j;
- map[i][j]=;
- }
- }
- bfs1(x1,y1);
- bfs2(x2,y2);
- for (int i=;i<=cnt;i++)
- {
- int nx=t[i].x,ny=t[i].y;
- if (!(dis1[nx][ny]+dis2[nx][ny]))continue;
- ans=min(ans,dis1[nx][ny]+dis2[nx][ny]);
- }
- printf("%d",ans);
- }
BZOJ1671: [Usaco2005 Dec]Knights of Ni的更多相关文章
- POJ3170 Bzoj1671 [Usaco2005 Dec]Knights of Ni 骑士
1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 281 Solved: 180 ...
- bzoj1671 [Usaco2005 Dec]Knights of Ni 骑士
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
- 1671: [Usaco2005 Dec]Knights of Ni 骑士
1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 254 Solved: 163 ...
- 【BZOJ】1671: [Usaco2005 Dec]Knights of Ni 骑士(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1671 从骑士bfs一次,然后从人bfs一次即可. #include <cstdio> # ...
- BZOJ_1671_[Usaco2005 Dec]Knights of Ni 骑士_BFS
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...
- [Usaco2005 Dec]Knights of Ni 骑士
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...
- BZOJ 1671: [Usaco2005 Dec]Knights of Ni 骑士 (bfs)
题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1671 题解: 按题意分别从贝茜和骑士bfs然后meet_in_middle.. 把一个逗号 ...
- bzoj 1671: [Usaco2005 Dec]Knights of Ni 骑士【bfs】
bfs预处理出每个点s和t的距离d1和d2(无法到达标为inf),然后在若干灌木丛格子(x,y)里取min(d1[x][y]+d2[x][y]) /* 0:贝茜可以通过的空地 1:由于各种原因而不可通 ...
随机推荐
- Junit 学习
一. 断言核心方法 示例代码: package com.test; import org.junit.Assert; import org.junit.Test; /** * @Title: test ...
- android与javascript相互调用
下面这一节来介绍android和javascript是怎么相互调用的,这样我们的UI界面设计起来就简单多了,而且UI设计起来也可以跨平台.现在有好多web app前台框架了,比如sencha和jque ...
- 我对Laravel ThinkPHP Yii symfony2 CI cakephp 的看法
这是我的真心体会,在尝试使用Laravel.ThinkPHP.Yii.symfony2.CI.cakephp.Yii2 之后的真实想法(default7#zbphp.com). 1)ThinkPHP ...
- EA+svn实现UML的版本号控制
一.安装软件 1.VisualSvn Server svnserver 2.Tortoise Svn svnclient 3.Slik-Subversion-1.7.8-x64版本号控制插件 4.En ...
- 关于 视频同步vsync 信号在不同一时候钟域採样问题
今天调试 视频 4k(3840 x 1920)的vsync信号(时钟为 297Mhz) 进入 170Mhz 的时钟域, 发现输出来的信号信号抖动特别厉害.后来才发现这是不同一时候钟域 造成的影响. 快 ...
- Java基础知识强化36:StringBuffer类之StringBuffer的概述
1. StringBuffer类概述: (1)String的缺陷: 我们如果对字符串进行拼接操作,每次拼接,都会构造一个新的String对象,既耗时,又浪费空间.如下图: (2)StringBuffe ...
- JavaScripts学习日记——DOM
DOM Document Object Model 文档对象模型 整合js和html css.控制html文档行为.DOM就是把页面当中所有内容全部封装成对象.HTML文档中万物皆对象.1.对象的分 ...
- netstat 命令详解
netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的状态信息,在我的计算机上执行netstat后,其输出结果为:netstat命令是一 ...
- linux stat命令
在Linux中,文件没有“创建时间”这个说法.Linux中的文件的时间属性只有三个:atime(Access time).mtime(Modified time).ctime(Change time) ...
- 重学《C#高级编程》(序)
小生码农一枚,以前只是看别人写博客,从来没有想过要自己写博文,突然之间“脑抽”想自己也写点什么,遂在博客园开通这个博客. 简单介绍下自己吧,本人90后,父母对我没有大的想法,只是希望我平安成长,多学习 ...