武士风度的牛(tyvj1074)
来源:互联网 发布:网络维护费用 编辑:程序博客网 时间:2024/06/10 06:21
武士风度的牛
背景 Background
农民John有很多牛,他想交易其中一头被Don称为The Knight的牛。这头牛有一个独一无二的超能力,在农场里像Knight一样地跳(就是我们熟悉的象棋中马的走法)。虽然这头神奇的牛不能跳到树上和石头上,但是它可以在牧场上随意跳,我们把牧场用一个x,y的坐标图来表示。
描述 Description
这头神奇的牛像其它牛一样喜欢吃草,给你一张地图,上面标注了The Knight的开始位置,树、灌木、石头以及其它障碍的位置,除此之外还有一捆草。现在你的任务是,确定The Knight要想吃到草,至少需要跳多少次。The Knight的位置用'K'来标记,障碍的位置用'*'来标记,草的位置用'H'来标记。
这里有一个地图的例子:
11 | . . . . . . . . . .
10 | . . . . * . . . . .
9 | . . . . . . . . . .
8 | . . . * . * . . . .
7 | . . . . . . . * . .
6 | . . * . . * . . . H
5 | * . . . . . . . . .
4 | . . . * . . . * . .
3 | . K . . . . . . . .
2 | . . . * . . . . . *
1 | . . * . . . . * . .
0 ----------------------
1
0 1 2 3 4 5 6 7 8 9 0
The Knight 可以按照下图中的A,B,C,D...这条路径用5次跳到草的地方(有可能其它路线的长度也是5):
11 | . . . . . . . . . .
10 | . . . . * . . . . .
9 | . . . . . . . . . .
8 | . . . * . * . . . .
7 | . . . . . . . * . .
6 | . . * . . * . . . F<
5 | * . B . . . . . . .
4 | . . . * C . . * E .
3 | .>A . . . . D . . .
2 | . . . * . . . . . *
1 | . . * . . . . * . .
0 ----------------------
1
0 1 2 3 4 5 6 7 8 9 0
输入格式 Input Format
第一行: 两个数,表示农场的列数(<=150)和行数(<=150)
第二行..结尾: 如题目描述的图。
输出格式 Output Format
一个数,表示跳跃的最小次数。
样例输入 Sample Input
10 11
..........
....*.....
..........
...*.*....
.......*..
..*..*...H
*.........
...*...*..
.K........
...*.....*
..*....*..
样例输出 Sample Output
5
===================
宽搜
注意一个问题,行列是否相反.
===================
const dx:array[1..8]of longint=(1,2, 2, 1,-1,-2,-2,-1); dy:array[1..8]of longint=(2,1,-1,-2,-2,-1, 1, 2);var map:array[-2..153,-2..153]of char; //开始在这里定义地图时没注意,最后下标越界了... m,n:longint; x1,y1,x2,y2:longint; h:array[0..22500,1..3]of longint;procedure init;begin assign(input,'p1074.in'); assign(output,'p1074.out'); reset(input); rewrite(output);end;procedure terminate;begin close(input); close(output); halt;end;procedure bfs;var l,r:longint; i:longint; x_,y_:longint;begin l:=0; r:=1; h[1,1]:=x1; h[1,2]:=y1; h[1,3]:=0; repeat inc(l); // l:=l mod 22500; for i:=1 to 8 do begin x_:=h[l,1]+dx[i]; y_:=h[l,2]+dy[i]; if map[x_,y_]<>'*' then begin if (x_=x2) and (y_=y2) then begin writeln(h[l,3]+1); terminate; end; map[x_,y_]:='*'; inc(r); // r:=r mod 22500; h[r,1]:=x_; h[r,2]:=y_; h[r,3]:=h[l,3]+1; end; end; until l>=r;end;procedure main;var i,j:longint;begin readln(n,m); for i:=-2 to 153 do for j:=-2 to 153 do map[i,j]:='*'; for i:=1 to m do begin for j:=1 to n do begin read(map[i,j]); if map[i,j]='K' then begin x1:=i; y1:=j; end; if map[i,j]='H' then begin x2:=i; y2:=j; end; end; readln; end; {for i:=1 to m do begin for j:=1 to n do write(map[i,j]); writeln; end;} bfs;end;begin init; main; terminate;end.
- 武士风度的牛(tyvj1074)
- 武士风度的牛
- 武士风度的牛(广搜)
- 武士风度的牛(暴力广搜)
- TYVJ-1074 武士风度的牛 BFS
- Problem 10:武士风度的牛
- TYVJ 1074 武士风度的牛
- 【codevs 1411】武士风度的牛
- 【codevs 1411】武士风度的牛
- C++ - 计蒜客 - 跳跃的最小次数(bfs)武士风度的牛
- 强者的风度
- 封印的武士
- 《最后的武士》观评
- 风度
- 二十后男人要有的风度
- 【转】黑泽明的《七武士》
- 黑泽明和他的电影(七武士)
- The Last Samurai 最后的武士**
- 英语写作短语100句
- Create Android virtual Device BY the Eclipse platform
- 作文要想得高分,用词多变是关键
- 在Iframe判断ExtJs tree控件选中的节点id并且传输到后台
- 很全的英语短语,可以防止你英文退化
- 武士风度的牛(tyvj1074)
- 全国重点学科最好的考研高校
- php实现整个目录拷贝(使用for循环)
- 2012考研计划时间安排表
- 国家A类,B类,c类
- ActiveX控件
- C++ 重要的 引文
- iPad2使用心得和应用推荐(不定期更新)
- 线程1例子