UVALive - 2689 Cricket Field

题意:求最大的空的矩形,要求不包含任何点

思路:边输入边记录,没增加一个点就将包含它的矩形切成四个小矩形

#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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值