bzoj:1687;poj 2434:[Usaco2005 Open]Navigating the City 城市交通
Description
Given a city map with E (1 <= E <= 40) east/west street locations and N (1 <= N <= 30) north/south street locations, create instructions for a taxi driver to navigate from the start of his route (marked 'S') to the end (marked 'E'). Each instruction is a direction (one of 'N', 'E', 'S', or 'W') followed by a space followed by an integer that tells how many blocks to drive in that direction. If multiple routes are available, your program should output the shortest route. The shortest route is guaranteed to exist and be unique.
The map is depicted as a grid of '+'s that represent intersections and a set of roads depicted as '-' and '|'. Buildings and other obstacles are shown as '.'s. Here is a typical map:
+-+-+.+-+-+
|...|.....|
+-+.+-+-+-+
..|.......|
S-+-+-+.E-+
The taxi should go east, north, west, north, east two blocks, and so on. See the output format and sample solution below for its complete route.
Input
* Lines 2..2*N: These lines each contain 2*E-1 characters and encode the map of the street. Every other input line gives the data for the east/west streets; the remaining lines show the north/south streets. The format should be clear from the example.
第1行:两个用空格隔开的整数N和E.
第2到2N行:每行有2E-I个字符,表示地图.
Output
Sample Input
3 6
+-+-+.+-+-+
|...|.....|
+-+.+-+-+-+
..|.......|
S-+-+-+.E-+
Sample Output
E 1
N 1
W 1
N 1
E 2
S 1
E 3
S 1
W 1
直接bfs,然后记录路径就行了……
#include<queue>
#include<cstdio>
#include<iostream>
using namespace std; struct na{
int x,y;
};
const int fx[]={,,,-},fy[]={,,-,};
int n,m;
char map[][];
int cm[][];
char c;
queue <na> q;
void pri(int x,int y){
int k,p;
for(;;){
k=cm[x][y];p=;
if (k==) printf("E ");else
if (k==) printf("S ");else
if (k==) printf("W ");else
printf("N ");
while(cm[x][y]==k){
x+=fx[k];
y+=fy[k];
if (map[x][y]=='+') p++;
}
if (map[x][y]=='E'){
printf("%d",p+);
return;
}
printf("%d\n",p);
}
}
int main(){
scanf("%d%d",&n,&m);
n=n*-;m=m*-;
for (int i=;i<n;i++)
for (int j=;j<m;j++){
c=getchar();
while(c=='\n') c=getchar();
map[i][j]=c;
if (c=='E'){
na tmp;
tmp.x=i;tmp.y=j;
q.push(tmp);
}
cm[i][j]=-;
}
while(!q.empty()){
na k=q.front();q.pop();
for (int i=;i<;i++){
na now=k;
now.x+=fx[i];now.y+=fy[i];
if (now.x<||now.y<||now.x>=n||now.y>=m) continue;
if (map[now.x][now.y]=='.') continue;
if (cm[now.x][now.y]==-){
cm[now.x][now.y]=i>?i-:i+;
if (map[now.x][now.y]=='S'){
pri(now.x,now.y);
return ;
}
q.push(now);
}
}
}
}
bzoj:1687;poj 2434:[Usaco2005 Open]Navigating the City 城市交通的更多相关文章
- Bzoj 1687: [Usaco2005 Open]Navigating the City 城市交通 广搜,深搜
1687: [Usaco2005 Open]Navigating the City 城市交通 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 122 So ...
- 1687: [Usaco2005 Open]Navigating the City 城市交通
1687: [Usaco2005 Open]Navigating the City 城市交通 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 94 Sol ...
- 【BZOJ】1687: [Usaco2005 Open]Navigating the City 城市交通(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1687 bfs后然后逆向找图即可.因为题目保证最短路唯一 #include <cstdio> ...
- poj 2434;bzoj 1686 [Usaco2005 Open]Waves 波纹
Description Input 第1行:四个用空格隔开的整数Pj Bi,B2,R. P(1≤P≤5)表示石子的个数,Bi(-5×100000≤Bi≤5×100000)和B2(-5×1000 ...
- 【BZOJ】【2434】【NOI2011】阿狸的打字机
AC自动机+DFS序+BIT 好题啊……orz PoPoQQQ 大爷 一道相似的题目:[BZOJ][3172][TJOI2013]单词 那道题也是在fail树上数有多少个点,只不过这题是在x的fail ...
- BZOJ.2287.[POJ Challenge]消失之物(退背包)
BZOJ 洛谷 退背包.和原DP的递推一样,再减去一次递推就行了. f[i][j] = f[i-1][j-w[i]] + f[i-1][j] f[i-1][j] = f[i][j] - f[i-1][ ...
- [BZOJ 2287/POJ openjudge1009/Luogu P4141] 消失之物
题面: 传送门:http://poj.openjudge.cn/practice/1009/ Solution DP+DP 首先,我们可以很轻松地求出所有物品都要的情况下的选择方案数,一个简单的满背包 ...
- BZOJ 1066 POJ 2711 [SCOI2007]蜥蜴
与POJ 1815 Friendship类似,该题之前也做过 目前处于TLE状态.样例已经通过 1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec Memory Limit: ...
- BZOJ 3362 POJ 1984 Navigation Nightmare 并与正确集中检查
标题效果:一些养殖场是由一些南北或东西向的道路互连. 镶上在不断的过程中会问两个农场是什么曼哈顿的距离,假设现在是不是通信.那么输出-1. 思维:并与正确集中检查,f[i]点i至father[i]距离 ...
随机推荐
- 【阿里聚安全·安全周刊】双十一背后的“霸下-七层流量清洗”系统| 大疆 VS “白帽子”,到底谁威胁了谁?
关键词:霸下-七层流量清洗系统丨大疆 VS "白帽子"丨抢购软件 "第一案"丨企业安全建设丨Aadhaar 数据泄漏丨朝鲜APT组织Lazarus丨31款违规A ...
- 个人的MySql配置总结
lower_case_table_names参数是用来设置MySQL是否让Schema和数据表大小写敏感,我测试的是在查询界面和MySQL控制台界面无法改变它的值,要在配置文件中改变(先关闭服务),一 ...
- Visual Studio Code 快捷键大全(Windows)
Visual Studio Code 是一款优秀的编辑器,非常适合编写 TS 以及 React .最近在学习 AngularJs 2,开始使用 VSCode,特意整理翻译了一下官网的快捷键.因为已经习 ...
- 童话故事 --- 什么是SQL Server Browser
高飞狗这几天特别郁闷,不知该如何通过TCP/IP协议连接SQL Server数据库.好在功夫不负有心人,经过几天的刻苦研究,终于得到了答案. 高飞狗呼叫UDP1434端口,"叮铃铃,叮铃铃- ...
- 转:Siri之父:语音交互或将主导未来十年发展
http://zhinengjiaohu.juhangye.com/201709/weixin_5664458.html Siri之父Adam Cheyer认为,语音交互很可能是未来十年内计算技术的一 ...
- 腾讯云主机 MySQL 远程访问配置方法
使用腾讯云主机安装 MySQL 之后,需要通过以下步骤进行配置以实现远程访问,主要分为两大部分 一.服务器端口配置 1.如果你的云主机配置了安全组,如果没有配置安全组就可以直接跳过“步骤1”的操作,否 ...
- 多线程下QAxObject指针为NULL的解决办法
项目中需要对Excel进行操作,把数据中的数据写入到Excel文件中.在数据量大的情况下,操作Excel是一件费时的操作. 但是执行到下列代码时就会出现空指针的情况: QAxObject *excel ...
- 快速恢复开发环境(系统还原后的思考,附上eclipse注释的xml配置文件)
1.Eclipse/Myeclipse的工作空间,不能放在系统盘 除非你的项目都有实时的云同步或SVN等,才能放在系统固态盘,不然你享受快速启动项目的同时,也需要承担系统奔溃后找不回项目的风险: 公司 ...
- Head First设计模式之外观模式
一.定义 外观模式提供了一个统一的接口,用来访问子系统中的一群接口.外观定义了一个高层接口,让子系统更容易使用. 外观模式不只是简化了接口,也将客户从组件的子系统中解耦. 外观和适配器可以包装许多类, ...
- docker for windows & dotnet core app
Step 1: 安装docker for windows Step 2: 从github 上 clone 源代码:https://github.com/dotnet/dotnet-docker-sam ...