Poj 3278 BFS(不多说话) Catch That Cow
2016-11-13 18:39
330 查看
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow
is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.
* Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute
* Teleporting: FJ can move from any point X to the point 2 × X in a single minute.
If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?
----------------------------------------------------------分割线-------------------------------------------------------------------------------
is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.
* Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute
* Teleporting: FJ can move from any point X to the point 2 × X in a single minute.
If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?
----------------------------------------------------------分割线-------------------------------------------------------------------------------
var n,k,head,tail,x:longint; step,que:array[0..1000000] of longint; t:array[0..1000000] of boolean; procedure ins(x:longint); begin t[x]:=false; inc(tail); que[tail]:=x; step[tail]:=step[head]+1; end; begin read(n,k); head:=1;tail:=1;que[1]:=n;step[1]:=0; fillchar(t,sizeof(t),true);t :=false; while head<=tail do begin x:=que[head]; if x=k then begin writeln(step[head]); break; end; if (x-1>=0) and t[x-1] then ins(x-1); if (x+1<=100000) and t[x+1] then ins(x+1); if (2*x<=100000) and t[2*x] then ins(2*x); inc(head); end; end.
相关文章推荐
- POJ - 3278-Catch That Cow(BFS)
- POJ - 3278 Catch That Cow(BFS)
- poj-3278-Catch That Cow【BFS】
- poj 3278 Catch That Cow(bfs)
- POJ-3278-Catch That Cow(BFS)
- POJ 3278 Catch That Cow(BFS广度优先搜索)
- poj 3278 Catch That Cow(经典bfs)
- bfs poj 3278 Catch That Cow+kuangbin搜索 C
- 2道裸BFS(POJ 3278 Catch That Cow / POJ 2251 Dungeon Master)
- Catch That Cow POJ - 3278 图论模型 BFS
- poj 3278 Catch That Cow (BFS)
- Problem C POJ 3278 Catch That Cow(三入口bfs)
- poj--3278--Catch That Cow(bfs)
- POJ - 3278 Catch That Cow ——BFS
- POJ 3278 Catch That Cow (bfs)
- [POJ 3278]Catch That Cow[BFS]
- POJ 3278 && HDU 2717 Catch That Cow(bfs)
- POJ 3278 Catch That Cow (BFS)
- poj3278 Catch That Cow BFS
- POJ3278,Catch That Cow,BFS...