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. Windows Server 2008 R2防火墙出站规则

    出战规则指Windows Server 2008 R2系统访问外部的某台计算机通信数据流. 配置防火墙阻止Windows Server 2008 R2系统通过IE软件访问外部的网站服务器,阻止Wind ...

  2. jQuery wrap wrapAll wrapInner使用

    jQuery wrap wrapAll wrapInner使用 <%@ page language="java" import="java.util.*" ...

  3. Linux内存管理之slab分配器

    slab分配器是什么? 参考:http://blog.csdn.net/vanbreaker/article/details/7664296 slab分配器是Linux内存管理中非常重要和复杂的一部分 ...

  4. 开源第三方登录组件OAuthLogin2.0 支持QQ,阿里巴巴,淘宝,京东,蘑菇街,有赞等平台

    Nuget地址:https://www.nuget.org/packages/OAuthLogin2.0/ 项目结构说明: AuthorizationProviders文件夹下主要存放内置的授权平台. ...

  5. 笔记:Ubuntu 上的Testlink 部署

    1.安装apache2 sudo apt-get install apache2 2. sudo /etc/init.d/apache2 restart 测试: Http:\localhost or ...

  6. PHP使用hash_algos函数计算哈希值,之间的性能排序

    PHP从5.1.2版本以上开始支持hash_algos函数,看这个名字就知道了,algos在英文中也表示算法的意思,hash_algos就是哈希算法,收集了一些常用的哈希算法,从5.1.2开始不同版本 ...

  7. 利用终端命令实现进入ntfs分区有两种方法。

    一.手动设置ubuntu自动挂载Windows分区方法:1.先用FDISK命令查看一下磁盘的UUID $sudo fdisk -l /dev/sda1 * 1 851 6835626 83 Linux ...

  8. 简单的Elf逆向Writeup

    ElfCrackMe1 html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acrony ...

  9. css3 3d变换和动画——回顾

    1.transform-style 属性指定嵌套原始是怎样在三维空间中呈现. 语法:transform-style: flat | preserve-3d flat 表示所有子元素在2D平面呈现. p ...

  10. block和delegate的区别

    代理  可读性高  大部分可以属性 block   写的代码少 一般作为参数通知   占用资源 无论是block还是delegate模式本质上都是回调,使用block,其优点是回调的block代码块直 ...