The main idea: there are n trees in a w * H grid, asking you to find the largest square in this grid, which cannot have a tree inside, and there can be trees on the edge.
Problem-solving ideas: Just beginning to think of violence to enumerate each point, the results found wrong, in fact, this problem is like UVA-1382 distant galaxy this problem, but this is to find a square, looking for a square and look like a rectangle, only need to take the smallest side of the rectangle can be
#include <cstdio>#include <algorithm>using namespace STD;#define MAXNstructpoint{intx, y;} P[MAXN];intN, W, H, Y[MAXN];BOOLcmpConstPoint A,ConstPoint B) {if(a.x = = b.x)returnA.y < B.y;returna.x < b.x;}voidInit () {scanf("%d%d%d", &n, &w, &h); for(inti =0; I < n; i++) {scanf("%d%d", &p[i].x, &P[I].Y); Y[i] = p[i].y; } Y[n] =0, Y[n +1] = H; Sort (y, y + n +2); Sort (p, p + N, CMP);}voidSolve () {intAns =0, XX, yy;intm = Unique (y, y + n +2)-Y; for(inti =0; I < m; i++) for(intj = i +1; J < M; J + +) {inth = y[j]-y[i], pre =0, W; for(intK =0; K < n; k++) {if(p[k].y <= Y[i] | | p[k].y >= Y[J])Continue; W = p[k].x-pre;if(Ans < min (w, h)) {ans = min (w,h); xx = pre; yy = Y[i]; } pre = p[k].x; } w = W-pre;if(Ans < min (h, W)) {ans = min (h,w); xx = pre; yy = Y[i]; } }printf("%d%d%d\n", xx, yy, ans);}intMain () {intTestscanf("%d", &test); while(test--) {init (); Solve ();if(test)printf("\ n"); }return 0;}
UVA-1312 Cricket Field Construction