题目大意,给出一个矩形区域,里面有一些点,求出空出的最大的正方形面积。
解题思路,每加进一个点就对现有的矩形进行一次切割,上下,左右个两个,最后再统计一下。
用的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;
}