1632: [Usaco2007 Feb]Lilypad Pond

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 404  Solved: 118
[Submit][Status][Discuss]

Description

Farmer John 建造了一个美丽的池塘,用于让他的牛们审美和锻炼。这个长方形的池子被分割成了 M 行和 N 列( 1 ≤ M ≤ 30 ; 1 ≤ N ≤ 30 ) 正方形格子的 。某些格子上有惊人的坚固的莲花,还有一些岩石,其余的只是美丽,纯净,湛蓝的水。 贝茜正在练习芭蕾舞,她从一个莲花跳跃到另一个莲花,当前位于一个莲花。她希望在莲花上一个一个的跳,目标是另一个给定莲花。她能跳既不入水,也不到一个岩石上。 令门外汉惊讶的是,贝茜的每次的跳跃像中国象棋的马一样:横向移动1,纵向移动2,或纵向移动1,横向移动2。贝茜有时可能会有多达8个选择的跳跃。 Farmer John 在观察贝茜的芭蕾舞联系,他意识到有时候贝茜有可能跳不到她想去的目的地,因为路上有些地方没有莲花。于是他想要添加几个莲花使贝茜能够完成任务。一贯节俭的Farmer John想添加最少数量的莲花。当然,莲花不能放在石头上。 请帮助Farmer John确定必须要添加的莲花的最少数量。在添加的莲花最少基础上,算出贝茜从起始点跳到目标点需要的最少的步数。最后,还要算出满足添加的莲花的最少数量时,跳跃最少步数的跳跃路径的条数。

Input

第 1 行: 两个整数 M , N

第 2..M + 1 行:第 i + 1 行,第 i + 1 行 有 N 个整数,表示该位置的状态: 0 为水; 1 为莲花; 2 为岩石; 3 为贝茜开始的位置; 4 为贝茜要去的目标位置.

Output

第 1 行: 一个整数: 需要添加的最少的莲花数. 如果无论如何贝茜也无法跳到,输出 -1.

第 2 行: 一个整数: 在添加的莲花最少基础上,贝茜从起始点跳到目标点需要的最少的步数。如果第1行输出-1,这行不输出。 第 3 行: 一个整数: 添加的莲花的最少数量时,跳跃步数为第2行输出的值的跳跃路径的条数 如果第1行输出-1,这行不输出。

Sample Input

4 8
0 0 0 1 0 0 0 0
0 0 0 0 0 2 0 1
0 0 0 0 0 4 0 0
3 0 0 0 0 0 1 0

Sample Output

2
6
2

输出说明

至少要添加2朵莲花,放在了'x'的位置。

0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0
0 x 0 0 0 2 0 1 0 0 0 0 0 2 0 1
0 0 0 0 x 4 0 0 0 0 x 0 x 4 0 0
3 0 0 0 0 0 1 0 3 0 0 0 0 0 1 0
贝茜至少要条6步,有以下两种方案

0 0 0 C 0 0 0 0 0 0 0 C 0 0 0 0
0 B 0 0 0 2 0 F 0 0 0 0 0 2 0 F
0 0 0 0 D G 0 0 0 0 B 0 D G 0 0
A 0 0 0 0 0 E 0 A 0 0 0 0 0 E 0

HINT

 

Source

Silver

题解:一道很萌的深搜题,其实道理也很简单,就是在搜索最优方案的时候顺带记录比对下总步数,以及方案数量即可。。。

居然神奇地拿了Rank5,估计很快就被虐下去的TT

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ const
xt:array[..] of longint=(,,-,-,,,-,-);
yt:array[..] of longint=(,-,,-,,-,,-);
var
i,j,k,l,m,n,ans,f,r,ex,ey:longint;
x,y:array[..] of longint;
a,b,c,d:array[..,..] of longint;
e:array[..,..] of int64;
procedure bfs;inline;
var nx,ny,ty,tx,i,j,k,l,ta:longint;
begin while f<>r do
begin
nx:=x[f];ny:=y[f];inc(f);
for k:= to do
begin
tx:=nx+xt[k];ty:=ny+yt[k];
if (tx<) or (ty<) or (tx>n) or (ty>m) or (a[tx,ty]=) then continue;
ta:=b[nx,ny]+longint(a[tx,ty]=);
if ta<b[tx,ty] then
begin
b[tx,ty]:=ta;
c[tx,ty]:=c[nx,ny]+;
e[tx,ty]:=e[nx,ny];
if d[tx,ty]<> then continue;
d[tx,ty]:=;x[r]:=tx;
y[r]:=ty;inc(r);
end
else
begin
if ta=b[tx,ty] then
begin
if (c[nx,ny]+)<c[tx,ty] then
begin
c[tx,ty]:=c[nx,ny]+;
e[tx,ty]:=e[nx,ny];
if d[tx,ty]<> then continue;
d[tx,ty]:=;
x[r]:=tx;y[r]:=ty;
inc(r);
end
else
begin
if (c[nx,ny]+)=c[tx,ty] then
begin
inc(e[tx,ty],e[nx,ny]);
if d[tx,ty]<> then continue;
d[tx,ty]:=;
x[r]:=tx;y[r]:=ty;inc(r);
end;
end;
end;
end;
end;
d[nx,ny]:=;
end;
end;
begin
f:=;r:=;
readln(n,m);
for i:= to n do
for j:= to m do
begin
read(a[i,j]);
if j=m then readln;
b[i,j]:=maxlongint;c[i,j]:=maxlongint;
if a[i,j]= then
begin
d[i,j]:=;
x[]:=i;y[]:=j;b[i,j]:=;
c[i,j]:=;
e[i,j]:=;
end
else
if a[i,j]= then
begin
ex:=i;ey:=j;
end;
end;
bfs;
if b[ex,ey]=maxlongint then
begin
writeln(-);
halt;
end
else
begin
writeln(b[ex,ey]);
writeln(c[ex,ey]);
writeln(e[ex,ey]);
end;
end.

1632: [Usaco2007 Feb]Lilypad Pond的更多相关文章

  1. BZOJ 1632: [Usaco2007 Feb]Lilypad Pond

    题目 1632: [Usaco2007 Feb]Lilypad Pond Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 390  Solved: 109[ ...

  2. 【BZOJ】1632: [Usaco2007 Feb]Lilypad Pond(bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1632 我简直是个sb... ... bfs都不会写.. 算方案还用2个bfs! 都不会整合到一个! ...

  3. BZOJ 1632 [Usaco2007 Feb]Lilypad Pond:spfa【同时更新:经过边的数量最小】【路径数量】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1632 题意: 有一个n*m的池塘.0代表水,1代表荷花,2代表岩石,3代表起点,4代表终点 ...

  4. bzoj 1632: [Usaco2007 Feb]Lilypad Pond【bfs】

    直接bfs,在过程中更新方案数即可 #include<iostream> #include<cstdio> #include<queue> using namesp ...

  5. bzoj1632 [Usaco2007 Feb]Lilypad Pond

    Description Farmer John 建造了一个美丽的池塘,用于让他的牛们审美和锻炼.这个长方形的池子被分割成了 M 行和 N 列( 1 ≤ M ≤ 30 ; 1 ≤ N ≤ 30 ) 正方 ...

  6. BZOJ1632: [Usaco2007 Feb]Lilypad Pond SPFA+最短路计数

    Description 为了让奶牛们娱乐和锻炼,农夫约翰建造了一个美丽的池塘.这个长方形的池子被分成了M行N列个方格(1≤M,N≤30).一些格子是坚固得令人惊讶的莲花,还有一些格子是岩石,其余的只是 ...

  7. BZOJ1698: [Usaco2007 Feb]Lilypad Pond 荷叶池塘

    一傻逼题调了两天.. n<=30 * m<=30的地图,0表示可以放平台,1表示本来有平台,2表示不能走,3起点4终点,走路方式为象棋的日字,求:从起点走到终点,至少要放多少平台,以及放平 ...

  8. [ USACO 2007 FEB ] Lilypad Pond (Silver)

    \(\\\) \(Description\) 一张\(N\times M\)的网格,已知起点和终点,其中有一些地方是落脚点,有一些地方是空地,还有一些地方是坏点. 现在要从起点到终点,每次移动走日字\ ...

  9. [ USACO 2007 FEB ] Lilypad Pond (Gold)

    \(\\\) \(Description\) 一张\(N\times M\)的网格,已知起点和终点,其中有一些地方是落脚点,有一些地方是空地,还有一些地方是坏点. 现在要从起点到终点,每次移动走日字\ ...

随机推荐

  1. 基于ASIO的协程库orchid简介

    什么是orchid? orchid是一个构建于boost库基础上的C++库,类似于python下的gevent/eventlet,为用户提供基于协程的并发模型. 什么是协程: 协程,即协作式程序,其思 ...

  2. H.264 SVC 与H.264 AVC

    分级视频编码技术实现一次性编码产生具有不同帧率.分辨率的视频压缩码流,然后根据不同网络带宽.不同的显示屏幕和终端解码能力选择需要传输的视频信息量,以此实现视频质量的自适应调整 AVC 实际上是 H.2 ...

  3. CodeForces 725A

    A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. Spring之循环依赖

    转:http://my.oschina.net/tryUcatchUfinallyU/blog/287936 概述 如何检测循环依赖 循环依赖如何解决 Spring如何解决循环依赖 主要的几个缓存 主 ...

  5. ECMAScript 6 笔记(五)

    Iterator和for...of循环 1. Iterator(遍历器)的概念 Iterator接口的目的,就是为所有数据结构,提供了一种统一的访问机制,即for...of循环 遍历器(Iterato ...

  6. Codeforce 712A Memory and Crow

    A. Memory and Crow time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  7. 初识PHP遗留下来的问题?

    待解决的问题: 1.写一个PHP脚本,显示用户输入的名称. 提示: <?php echo $_POST["username"];?>! <?php echo &q ...

  8. Thinkpad W540通过扩展坞连接显示器后蓝屏原因

    问题:Thinkpad W540通过扩展坞连接显示器后蓝屏 描述:直接扩展连接显示器重启电脑,一直黑屏,等待光标,进不了桌面.分离扩展,进入后,再连接显示器,蓝屏死机. 解决:用尽办法,重装显示驱动, ...

  9. 数字信号处理MATLAB简单序列

    数字信号处理应用的几个基本序列: 1 单位样本序列 function mainImseq() clc clear disp('生成抽样序列'); y=imseq(,,); %调用样本函数,此时序列下标 ...

  10. bootstrap3 响应式布局栅格式布局

    抓住重点 下面开始实现Bootstrap版本3的Demo 案例 首先去官方网站  http://www.bootcss.com/ 下载 点击 进入 点击 进入 下载 把 相关的js和css 拷贝到项目 ...