题意:求最大的空的矩形,要求不包含任何点
思路:边输入边记录,没增加一个点就将包含它的矩形切成四个小矩形
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1000005; struct node{ int x,y; int w,h; }arr[MAXN]; int n,W,H; int main(){ int t; scanf("%d",&t); while (t--){ scanf("%d%d%d",&n,&W,&H); int cnt = 0; arr[cnt].x = arr[cnt].y = 0; arr[cnt].w = W,arr[cnt].h = H; cnt++; for (int i = 0; i < n; i++){ int a,b; scanf("%d%d",&a,&b); for (int j = 0; j < cnt; j++){ int x = arr[j].x,y = arr[j].y; int w = arr[j].w,h = arr[j].h; if (a > x && a < x+w && b > y && b < y+h){ arr[cnt].x = x,arr[cnt].y = y; arr[cnt].w = w,arr[cnt++].h = b - y; arr[cnt].x = x,arr[cnt].y = y; arr[cnt].w = a-x,arr[cnt++].h = h; arr[cnt].x = a,arr[cnt].y = y; arr[cnt].w = w-a+x,arr[cnt++].h = h; arr[cnt].x = x,arr[cnt].y = b; arr[cnt].w = w,arr[cnt++].h = h-b+y; arr[j].w = 0; } } } int ans = 0,sign; for (int i = 0; i < cnt; i++){ int temp = min(arr[i].w,arr[i].h); if (ans < temp){ ans = temp; sign = i; } } printf("%d %d %d\n",arr[sign].x,arr[sign].y,ans); if (t) printf("\n"); } return 0; }