Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* ZADANIE 4 *)
- let wysokosc mapa =
- let s1 = Array.length mapa and s2 = Array.length (mapa.(0)) in
- let hmax = let h = ref mapa.(0).(0) in begin
- for i = 0 to s1 - 1 do
- for j = 0 to s2 - 1 do
- if mapa.(i).(j) > !h then begin
- h := mapa.(i).(j)
- end
- done
- done;
- !h
- end in
- let warunek h =
- let odw = Array.make_matrix s1 s2 false in
- let rec dfs x y =
- if mapa.(x).(y) > h then () else
- begin
- odw.(x).(y) <- true;
- if (x > 0) && not (odw.(x - 1).(y)) then dfs (x - 1) y;
- if (y > 0) && not (odw.(x).(y - 1)) then dfs x (y - 1);
- if (x < s1 - 1) && not (odw.(x + 1).(y)) then dfs (x + 1) y;
- if (y < s2 - 1) && not (odw.(x).(y + 1)) then dfs x (y + 1);
- end
- in dfs 0 0; odw.(s1 - 1).(s2 - 1)
- in
- let kon = ref hmax and pocz = ref 0 in
- while !kon - !pocz > 1
- do
- let mid = (!kon + !pocz) / 2 in
- if warunek mid
- then
- kon := mid
- else
- pocz := mid;
- done; !kon;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement