1687: [Usaco2005 Open]Navigating the City 城市交通

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 94  Solved: 73
[Submit][Status][Discuss]

Description

    由于牛奶市场的需求,奶牛必须前往城市,但是唯一可用的交通工具是出租车.教会奶牛如何在城市里打的.
    给出一个城市地图,东西街区E(1≤E≤40),南北街区N(1≤N≤30).制作一个开车指南给出租车司机,告诉他如何从起点(用S表示)到终点(用E表示).每一个条目用空格分成两部分,第一个部分是方向(N,E,S,W之一),第二个是一个整数,表示要沿着这个方向开几个十字路口.如果存在多条路线,你应该给出最短的.数据保证,最短的路径存在且唯一.    地图中“+”表示十字路口,道路用“I”和“一”表示.建筑和其他设施用“.”表示.下面是一张地图:
 
 
    出租车可以沿着东,北,西,北,东开两个十字路口,以此类推.具体将由样例给出
 

Input

第1行:两个用空格隔开的整数N和E.

第2到2N行:每行有2E-I个字符,表示地图.

Output

每行有一个表示方向的字母和一个表示要开几个十字路口的数字表示.

Sample Input

Sample Input

 

Sample Output

E 1
N 1
W 1
N 1
E 2
S 1
E 3
S 1
W 1

HINT

 

Source

Silver

题解:一开始没仔细看题的时候以为是灌水法。。。可是后来想到貌似不见得就一条路径,而且题目中貌似说了要最短路径

不知道正解是啥,反正我还是一如既往的逗比——以地图上每个+符号(S、E也算)为节点,建立无向图,然后就成了求最短路径的问题了,然后就是神烦的边spfa边记录路径了,话说这道水题居然写了我好久唉TT

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ const dir:array[..] of char=('N','E','S','W');
type
point=^node;
node=record
g,w,q:longint;
next:point;
end;
var
i,j,k,l,m,n,x0,y0,x1,y1,x,y,f,r,s,t,v:longint;
map:array[..,..] of longint;
a:array[..] of point;
b,c,g:array[..] of longint;
d:array[..] of longint;
e,h:array[..,..] of longint;
ch:char;
p:point;
procedure add(x,y,z,t:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;
p^.q:=t;p^.next:=a[x];a[x]:=p;
end;
begin
fillchar(map,sizeof(map),);
readln(n,m);
n:=n*-;m:=m*-;
for i:= to n do
begin
for j:= to m do
begin
read(ch);
case upcase(ch) of
'S':begin
map[i,j]:=-;
x0:=i;y0:=j;
end;
'E':begin
map[i,j]:=-;
x1:=i;y1:=j;
end;
'.':map[i,j]:=;
'-':map[i,j]:=-;
'|':map[i,j]:=-;
'+':map[i,j]:=-;
end;
end;
readln;
end;
s:=;t:=;v:=;
for i:= to n do
for j:= to m do
if map[i,j]=- then
begin
inc(v);
map[i,j]:=v;
if (x0=i) and (y0=j) then s:=v;
if (x1=i) and (y1=j) then t:=v;
end;
for i:= to n do
for j:= to m do
begin
if map[i-,j]<> then
begin
x:=i-;y:=j;
while map[x,y]=- do dec(x);
if map[x,y]> then add(map[i,j],map[x,y],,);
end;
if map[i+,j]<> then
begin
x:=i+;y:=j;
while map[x,y]=- do inc(x);
if map[x,y]> then add(map[i,j],map[x,y],,);
end;
if map[i,j-]<> then
begin
x:=i;y:=j-;
while map[x,y]=- do dec(y);
if map[x,y]> then add(map[i,j],map[x,y],,);
end;
if map[i,j+]<> then
begin
x:=i;y:=j+;
while map[x,y]=- do inc(y);
if map[x,y]> then add(map[i,j],map[x,y],,);
end;
end;
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),);
fillchar(b,sizeof(b),);
fillchar(e,sizeof(e),);
d[]:=s;f:=;r:=;g[s]:=;c[s]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=) or ((c[p^.g]>) and (c[p^.g]>(c[d[f]]+p^.w))) then
begin
c[p^.g]:=c[d[f]]+p^.w;
b[p^.g]:=d[f];
e[p^.g,]:=p^.q;e[p^.g,]:=p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
inc(f);
g[d[f]]:=;
end;
for i:= to v do dec(c[i]);
i:=;fillchar(h,sizeof(h),);
while t<> do
begin
inc(i);
h[i,]:=e[t,];
h[i,]:=e[t,];
t:=b[t];
end;
v:=i-;
for i:= to v div do
begin
j:=h[i,];h[i,]:=h[v+-i,];h[v+-i,]:=j;
j:=h[i,];h[i,]:=h[v+-i,];h[v+-i,]:=j;
end;
inc(v);h[v,]:=;h[v,]:=;
j:=h[,];k:=h[,];
for i:= to v do
begin
if h[i,]=j then
k:=k+h[i,]
else
begin
writeln(dir[j],' ',k);
k:=h[i,];j:=h[i,];
end;
end;
readln;
end.

1687: [Usaco2005 Open]Navigating the City 城市交通的更多相关文章

  1. Bzoj 1687: [Usaco2005 Open]Navigating the City 城市交通 广搜,深搜

    1687: [Usaco2005 Open]Navigating the City 城市交通 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 122  So ...

  2. 【BZOJ】1687: [Usaco2005 Open]Navigating the City 城市交通(bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1687 bfs后然后逆向找图即可.因为题目保证最短路唯一 #include <cstdio> ...

  3. bzoj:1687;poj 2434:[Usaco2005 Open]Navigating the City 城市交通

    Description A dip in the milk market has forced the cows to move to the city. The only employment av ...

  4. usaco silver

    大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草   裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...

  5. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. [USACO2005][POJ3044]City Skyline(贪心+单调栈)

    题目:http://poj.org/problem?id=3044 题意:以坐标的形式给出一张图,表示一些楼房的正视图,求出楼房的最少个数. 分析:和小学常做的立方体问题很像,很容易想到一个贪心方法, ...

  9. bzoj1683[Usaco2005 Nov]City skyline 城市地平线

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1683 Input 第1行:2个用空格隔开的整数N和W. 第2到N+1行:每行包括2个用空格 ...

随机推荐

  1. 第四组UI组件:AdapterView及子类

    AdapterView组件是一组重要的组件,AdapterView本省是一个抽象基类,它派生的子类在用法上十分相似,只是显示界面与一定的区别,因此这次针对它们的共性集中讲解,并突出介绍他们的区别. A ...

  2. Java Ant Could not find the main class: org.eclipse.ant.internal.launching.remote.InternalAntRunner. Program

    参考:http://blog.csdn.net/jiangtaoking/article/details/49151763 The solution is to go to Run as → Exte ...

  3. Lazy.js : 让 JavaScript 变懒

    Lazy.js : 让 JavaScript 变懒 http://segmentfault.com/a/1190000000358463

  4. linux下的Source命令的基本功能

    source命令用法:source FileName作用:在当前bash环境下读取并执行FileName中的命令.注:该命令通常用命令“.”来替代.如:source .bash_rc 与 . .bas ...

  5. Angularjs^1.2.9 搜索关键字高亮显示

    需求分析: 根据关键字搜索网页内容,并且高亮显示内容中的关键字细节分析: 1.每次执行搜索操作,需清空上一次结果 2.需区分html标签和正常文本内容,否则为关键字添加样式以后会出现标签内容被显示的情 ...

  6. NodeJS Stream 四:Writable

    什么是可写流 可写流是对数据流向设备的抽象,用来消费上游流过来的数据,通过可写流程序可以把数据写入设备,常见的是本地磁盘文件或者 TCP.HTTP 等网络响应. 看一个之前用过的例子 process. ...

  7. redis的配置详解

    redis 127.0.0.1:6379> CONFIG GET loglevel 1) "loglevel" 2) "notice" Redis 的配置 ...

  8. HDU3410(单调队列)

    Passing the Message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. angular表格分页

    <!doctype html> <html lang="en" > <head> <meta charset="UTF-8&qu ...

  10. spring+struts2+ibatis 框架整合以及解析

    一. spring+struts2+ibatis 框架 搭建教程 参考:http://biancheng.dnbcw.net/linux/394565.html 二.分层 1.dao: 数据访问层(增 ...