The main idea: the problem of test instructions, so difficult to understand.
That is, if the point is the top of the mountain (height is h), then the point as the center, outward radiation, walk the height of more than h-d point, to reach another higher than the point
This indicates that the height of the order from large to small, in turn with a high point (assuming the height of h) as the core radiation, if the height of less than equals h-d, indicating blocked, and stop at that place
Conversely, if a height greater than h-d is encountered and is not dyed, then it is dyed
If the height is greater than h-d, and is stained, it means that you can go to another higher point, then this is not the peak.
If you bump into the same height as the point, the top of the mountain will add 1.
Here there is a mistake, write the code when the M written N (when the definition of the array, originally HIGHT[M][M], the result is written hight[n][n], here N = 250010,m = 510), the results have been CE, very depressed, but the computer compiled on the
Later, I pulled the definition of the structure behind me, and I made a mistake in compiling the computer, and there was not enough space.
This is a bit depressing, the definition of the structure of the Order also affect the compilation?
If there is a great God, I hope to tell you.
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace STD;#define N 250010#define M 510structNode {intX, Y, H;} Node[n];intdir[4][2] = {{-1,0}, {1,0}, {0, -1}, {0,1}};intAns, H, W, D;intCOLOR[M][M];intHIGHT[M][M];BOOLcmpConstNode &a,ConstNode &b) {returnA.h > B.h;}structtmp_node{intx, y; Tmp_node () {} tmp_node (intXintY): X (x), Y (y) {}};voidBFsintu) {BOOLFlag =true;inttot =1, Lim = node[u].h-d, high = node[u].h; queue<tmp_node>Q; Q.push (Tmp_node (node[u].x, node[u].y)); COLOR[NODE[U].X][NODE[U].Y] = high; while(! Q.empty ()) {Tmp_node t = Q.front (); Q.pop (); for(inti =0; I <4; i++) {intx = t.x + dir[i][0];inty = t.y + dir[i][1];if(x >= H | | x <0|| Y >= W | | Y <0)Continue;if(Hight[x][y] <= Lim)Continue;if(Color[x][y]! =-1) {if(Color[x][y]! = high) flag =false;Continue; }if(Color[x][y] = =-1) {Color[x][y] = high; Q.push (Tmp_node (x, y)); }if(Hight[x][y] = = high) tot++; } }if(flag) Ans + = tot;}voidSolve () {Sort (node, node + H * W, CMP);memset(Color,-1,sizeof(color)); Ans =0; for(inti =0; I < H * W; i++)if(COLOR[NODE[I].X][NODE[I].Y] = =-1) BFS (i);printf("%d\n", Ans);}intMain () {intTestscanf("%d", &test); while(test--) {scanf("%d%d%d", &h, &w, &d); for(inti =0; i < H; i++) for(intj =0; J < W; J + +) {scanf("%d", &node[i * W + j].h); Node[i * W + j].x = i; Node[i * W + j].y = j; HIGHT[I][J] = node[i * W + j].h; } solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVALive-3977 summits (BFS dyeing)