Original question:
http://172.16.0.132/senior/#contest/show/2041/2 topic Description:
As a geologist's jih, the field expedition was carried out in order to draw a map. At the end of the expedition, he got a map of the ground height of n*m. For scientific research, JIH defines a mountain called the D-Mountain. A height of h is called the D-Mountain, and only the satisfaction from here can not reach a higher place without passing a place less than or equal to h-d. Jih is wrestling with how to divide the gift, the task of marking the D-Mountain will be handed over to you. Input:
First line N,m,d
The second line begins with a n*m matrix representing the map, separated by a space. Output:
Outputs the number of D-peaks. Sample Input:
6 10 2
0 0 0 0 0 0 0 0 0 0
0 1 2 1 1 1 1 0 1 0
0 2 1 2 1 3 1 0 0 0
0 1 2 1 3 3 1 1 0 0
0 2 1 2 1 1 1 0 2 0
0 0 0 0 0 0 0 0 0 0 sample output:
4 data range limits:
30% n,m<=10
100% n,m<=500 Tips:
Analysis:
The
is difficult to reverse, with a total of points-illegal points, that is, a legitimate point.
enumerates every point, the brute-run answer is judged by memory optimization, and if the height of the current point is found to be >h-d and is not traversed, exit (true) else exit (false);
every time an illegal point is found, it is dec (ans);
If the number of points running is >n*m, the exit is dropped directly.
violence can be wide-search, can also be deep search. implementation:
Uses math;
Const U:ARRAY[1..4,1..2]OF longint= ((0,1), (1,0), (0,-1), ( -1,0));
var ans,n,m,d,i,j,maxn:longint;
A,f:array[0..501,0..501]of Longint;
Bz:array[0..501,0..501]of Boolean;
function DG (X,y,h,sum,tot:longint): boolean;
var i,xx,yy:longint;
Begin F[x,y]:=sum;
If A[x,y]>h then begin DEC (ANS);
Exit (TRUE);
End
if (a[x,y]=h) and (Bz[x,y]) THEN begin DEC (ANS);
Exit (TRUE);
End
If Tot>n*m then exit (false);
For i:=1 to 4 do begin xx:=x+u[i,1];
yy:=y+u[i,2]; if (xx>0) and (Xx<=n) and (yy>0) and (yy<=m) then if (f[xx,yy]<>sum) and (a[xx,yy]>h-
d) and (DG (XX,YY,H,SUM,TOT+1)) then exit (true);
End
Exit (FALSE);
End
Begin READLN (N,M,D);
For I:=1 to N does for j:=1 to M do Begin read (a[i,j]);
Maxn:=max (A[I,J],MAXN);
End
Ans:=n*m; For I:=1 to N does for j:=1 to M does if A[i,j]<>maxn then BZ[I,J]:=DG (i,j,a[i,j
],i*m+j,0);
Writeln (ANS);
End.