Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let sadzawka arr start =
- let n = Array.length arr in
- let d = Array.make_matrix n n 0 in
- let q = Queue.create () in
- Queue.add start q;
- let (x,y) = start in
- d.(x).(y) <- arr.(x).(y);
- let decision (x1,y1) (x2,y2) =
- let m = min d.(x1).(y1) arr.(x2).(y2) in
- if(m > d.(x2).(y2)) then (d.(x2).(y2) <- m; true)
- else false
- in
- while (Queue.is_empty q <> true)
- do
- let (ci,cj) = Queue.take q in
- if ci>0 then
- if decision (ci,cj) (ci-1,cj) then (Queue.add (ci-1,cj) q;);
- if ci<n-1 then
- if decision (ci,cj) (ci+1,cj) then (Queue.add (ci+1,cj) q;);
- if cj>0 then
- if decision (ci,cj) (ci,cj-1) then (Queue.add (ci,cj-1) q;);
- if cj<n-1 then
- if decision (ci,cj) (ci,cj+1) then (Queue.add (ci,cj+1) q;);
- done;
- let maxi = ref 0 in
- for i = 0 to n-1
- do
- if d.(0).(i) > !maxi then (maxi:=d.(0).(i););
- if d.(i).(0) > !maxi then (maxi:=d.(i).(0););
- if d.(n-1).(i) > !maxi then (maxi:=d.(n-1).(i););
- if d.(i).(n-1) > !maxi then (maxi:=d.(i).(n-1););
- done;
- !maxi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement