1687: [Usaco2005 Open]Navigating the City 城市交通
1687: [Usaco2005 Open]Navigating the City 城市交通
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 94 Solved: 73
[Submit][Status][Discuss]
Description
.jpg)
Input
第1行:两个用空格隔开的整数N和E.
第2到2N行:每行有2E-I个字符,表示地图.
Output
每行有一个表示方向的字母和一个表示要开几个十字路口的数字表示.
Sample Input
.jpg)
Sample Input
Sample Output
N 1
W 1
N 1
E 2
S 1
E 3
S 1
W 1
HINT
Source
题解:一开始没仔细看题的时候以为是灌水法。。。可是后来想到貌似不见得就一条路径,而且题目中貌似说了要最短路径
不知道正解是啥,反正我还是一如既往的逗比——以地图上每个+符号(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 城市交通的更多相关文章
- Bzoj 1687: [Usaco2005 Open]Navigating the City 城市交通 广搜,深搜
1687: [Usaco2005 Open]Navigating the City 城市交通 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 122 So ...
- 【BZOJ】1687: [Usaco2005 Open]Navigating the City 城市交通(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1687 bfs后然后逆向找图即可.因为题目保证最短路唯一 #include <cstdio> ...
- 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 ...
- usaco silver
大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草 裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- [USACO2005][POJ3044]City Skyline(贪心+单调栈)
题目:http://poj.org/problem?id=3044 题意:以坐标的形式给出一张图,表示一些楼房的正视图,求出楼房的最少个数. 分析:和小学常做的立方体问题很像,很容易想到一个贪心方法, ...
- bzoj1683[Usaco2005 Nov]City skyline 城市地平线
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1683 Input 第1行:2个用空格隔开的整数N和W. 第2到N+1行:每行包括2个用空格 ...
随机推荐
- 我用Cocos2d-x模拟《Love Live!学院偶像祭》的Live场景(三)
[前言和思路整理] 千呼万唤Shi出来啊(好像也没人呼唤),最近公司项目紧,闲暇时间少更得慢,请见谅. 上一章我们分析并实现了打击物件类BeatObject,和它的父节点BeatObjectColum ...
- WCF服务发布到IIS中去 在WCF调试
第一个WCF程序 1. 新建立空白解决方案,并在解决方案中新建项目,项目类型为:WCF服务应用程序.建立完成后如下图所示: 2.删除系统生成的两个文件IService1.cs与Service1.svc ...
- table固定前两列和最后一列,其他滑动显示
网上搜的基本都是4个table做的,数据处理比较麻烦,写了个一个table的,此示例只固定了前两列和最后一列,和网上的不太一样. 网上搜的基本都是4个table做的,数据处理比较麻烦,写了个一个tab ...
- 自动化测试框架中关于selenium api的二次封装
不多说,直接看代码如下: #coding:utf-8 from selenium import webdriver from selenium.webdriver.common.action_chai ...
- 我的Linux软件集
把我常用的软件记下来,以后重装安装的时候方便一些- 这个博文会不断更新的- 开发工具类 Monodevelop 编写C#控制台程序和GTK#窗口程序,很好,虽然没有VS强大,但是够用了 CodeBlo ...
- 理解Window和WindowManager
Window表示一个窗口的概念,Window是一个抽象类,它的具体实现是PhoneWindow.创建一个Window,需要通过WindowManager即可完成,WindowManager是外界访问W ...
- UITableView、UICollectionView行高/尺寸自适应
UITableView 我们都知道UITableView从iOS 8开始实现行高的自适应相对比较简单,首先必须设置estimatedRowHeight给出预估高度,设置rowHeight为UITabl ...
- block之---循环引用
block内部引用外界对象的原则:block会对他内部所有的强指针进行强引用. 验证原理: 在主控制器中modal出ModalVC控制器,ModalVC中有强引用的block属性,在block内部使用 ...
- github在windows下的安装和基本使用
1.在win下安装github时花费的时间是非常长的,有时还会出现因各种原因安装不成功.离线包本地安装方便的解决了此问题.点击http://pan.baidu.com/s/1boGrNLP可下载,解压 ...
- bugly集成了Tinker热更新
介绍 热更新能力是Bugly为解决开发者紧急修复线上bug,而无需重新发版让用户无感知就能把问题修复的一项能力.Bugly目前采用微信Tinker的开源方案,开发者只需要集成我们提供的SDK就可以实现 ...