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个用空格 ...
随机推荐
- winform的Textbox设置只读之后ForeColor无效的解决方法
winform的Textbox设置只读之后ForeColor无效. 通过以下方法就可以解决: 设置为只读之后,把BackColor改一下,然后运行一下窗口,再设置ForeColor就没问题了. tbT ...
- MyBatis与Spring集成
beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- spring mvc rest 方式
handler中编写方式: @RequestMapping("/{userName}/ajaxUser3.do") @ResponseBody public UserInfo aj ...
- 基于ASIO的协程与网络编程
协程 协程,即协作式程序,其思想是,一系列互相依赖的协程间依次使用CPU,每次只有一个协程工作,而其他协程处于休眠状态.协程可以在运行期间的某个点上暂停执行,并在恢复运行时从暂停的点上继续执行. 协程 ...
- 导入礼包时,遇到file_get_contents读取的文本,去除空格、换行等的方法
解决方法:正则替换: 代码:$gift_code_str = preg_replace('/((\s)*(\n)+(\s)*) /i ',',',file_get_contents($gift_cod ...
- echarts 显示下载按钮,echarts 自定义按钮,echarts 添加按钮
echarts 显示下载按钮,echarts 自定义按钮,echarts 添加按钮 >>>>>>>>>>>>>>&g ...
- 初识servlet--未完成
servlet到底是什么呢?今天我们一起看一下. 首先说下servlet是干啥的.servlet主要干这么一个事情:创建动态的问页面. servlet主要的功能是,访问外网,连接外部接口.它可以做如下 ...
- 模仿jquery的fileupload插件
仅需要new一个对象,将上传后台的url和点击触发上传的元素id传给对象,就可以自从实现上传 暂不支持IE <html> <body> <a href="#&q ...
- JAVA中浮点数显示
//Java小数点后留两位 double num1 =11; double num2 =21; String num3 =""; //函数可以确定十进制数的显示格式:百分数,限定小 ...
- docker - 容器里安装mysql
在docker中安装mysql ubuntu官方镜像是精简的ubuntu系统,很多软件和库没有安装,所以直接安装mysql的话依赖较多,建议直接从源码编译安装mysql 通过命令行安装 先启动一个容器 ...