UVA--1312--Cricket Field

题目大意,给出一个矩形区域,里面有一些点,求出空出的最大的正方形面积。

解题思路,每加进一个点就对现有的矩形进行一次切割,上下,左右个两个,最后再统计一下。

用的stl里面的队列,UVA上0.5s过了,POJ上过不了,又不想改成数组。。。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
struct node
{
    int x1,x2;
    int y1,y2;
    int flag;
    node(int x1,int y1,int x2,int y2,int flag):x1(x1),y1(y1),x2(x2),y2(y2),flag(flag){}
};
int n,m,k;
int flag;
queue<node> q;

void cut(int x,int y)
{
    int c=0;
    while(!q.empty())
    {
        node u=q.front();
        if(flag==u.flag)break;
        q.pop();

        if(x>u.x1&&x<u.x2&&y>u.y1&&y<u.y2)
        {
            //Çиî
            c++;
            node a(u.x1,u.y1,u.x2,y,flag);
            node b(u.x1,y,u.x2,u.y2,flag);
            node c(u.x1,u.y1,x,u.y2,flag);
            node d(x,u.y1,u.x2,u.y2,flag);
            q.push(a);q.push(b);q.push(c);q.push(d);
        }
        else
        {
            u.flag=flag;
            q.push(u);
        }
    }
    //cout<<"¸î"<<c<<"´Î"<<endl;
}

void op()
{
    queue<node> pp(q);
    while(!pp.empty())
    {
        node u=pp.front();pp.pop();
        printf("(%d %d)-(%d %d) ",u.x1,u.y1,u.x2,u.y2);
    }
    cout<<endl;
}

void solve()
{
    int x,y;
    flag=0;
    while(!q.empty())q.pop();
    scanf("%d%d%d",&k,&n,&m);
    node u(0,0,n,m,flag);
    q.push(u);
    for(int i=0;i<k;i++)
    {
        scanf("%d%d",&x,&y);
        flag++;
        cut(x,y);
    }
    int ansx=-1,ansy=-1,ansl=0;
    while(!q.empty())
    {
        u=q.front();q.pop();
        int temp=min(u.y2-u.y1,u.x2-u.x1);
        if(temp>ansl)
        {
            ansl=temp;
            ansx=u.x1;
            ansy=u.y1;
        }
    }
    printf("%d %d %d\n",ansx,ansy,ansl);
}

int main()
{
    //freopen("2173.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        solve();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值