HDU 5128 The E-pang Palace

题意:枚举矩形,注意会有回字形这种情况出现


#include<bits/stdc++.h>
using namespace std;
const int maxn = 50;
int n;
struct point
{
	int x,y;
	bool operator < (const point &a)const
	{
		if (x==a.x)
			return y<a.y;
		return x<a.x;
	}
}p[maxn];
struct ret
{
	point p1,p2;
	int area;
}r[maxn*maxn];
int check(int i,int j)
{
	if (r[i].p2.x<r[j].p1.x)return 1;
	if (r[i].p2.y<r[j].p1.y)return 1;
	if (r[i].p1.x>r[j].p2.x)return 1;
	if (r[i].p1.y>r[j].p2.y)return 1;
    if (r[i].p1.x<r[j].p1.x && r[i].p1.y<r[j].p1.y && r[i].p2.x>r[j].p2.x && r[i].p2.y>r[j].p2.y)
		return 2;
	else
	   return 0;
}
int vis[250][250];
int main()
{
	while (scanf("%d",&n)!=EOF&&n)
	{
		memset(vis,0,sizeof(vis));
		for (int i = 0;i<n;i++)
		{
			scanf("%d%d",&p[i].x,&p[i].y);
			vis[p[i].x][p[i].y]=1;
		}
		sort(p,p+n);
		int cnt = 0;
		for (int i = 0;i<n;i++)
		{
			for (int j = i+1;j<n;j++)
			{
				if (p[j].x>p[i].x && p[j].y>p[i].y)
				{
					if (vis[p[i].x][p[j].y] && vis[p[j].x][p[i].y])
					{
						r[cnt].p1.x=p[i].x;
						r[cnt].p1.y=p[i].y;
						r[cnt].p2.x=p[j].x;
						r[cnt].p2.y=p[j].y;
                        r[cnt++].area=(p[j].x-p[i].x)*(p[j].y-p[i].y);
					}
				}
			}
		}
		int ans = -1;
		for (int i = 0;i<cnt;i++)
			for (int j = 0;j<cnt;j++)
			{
				if (check(i,j)==1)
					ans = max(ans,r[i].area+r[j].area);
				else if (check(i,j)==2)
					ans = max(ans,max(r[i].area,r[j].area));
			}
		if (ans==-1)
			puts("imp");
		else
			printf("%d\n",ans);
	}
}


Description

E-pang Palace was built in Qin dynasty by Emperor Qin Shihuang in Xianyang, Shanxi Province. It was the largest palace ever built by human. It was so large and so magnificent that after many years of construction, it still was not completed. Building the great wall, E-pang Palace and Qin Shihuang's tomb cost so much labor and human lives that people rose to fight against Qin Shihuang's regime. 

Xiang Yu and Liu Bang were two rebel leaders at that time. Liu Bang captured Xianyang -- the capital of Qin. Xiang Yu was very angry about this, and he commanded his army to march to Xianyang. Xiang Yu was the bravest and the strongest warrior at that time, and his army was much more than Liu Bang's. So Liu Bang was frighten and retreated from Xianyang, leaving all treasures in the grand E-pang Palace untouched. When Xiang Yu took Xianyang, he burned E-pang Palce. The fire lasted for more than three months, renouncing the end of Qin dynasty. 

Several years later, Liu Bang defeated Xiangyu and became the first emperor of Han dynasty. He went back to E-pang Palace but saw only some pillars left. Zhang Liang and Xiao He were Liu Bang's two most important ministers, so Liu Bang wanted to give them some awards. Liu Bang told them: "You guys can make two rectangular fences in E-pang Palace, then the land inside the fences will belongs to you. But the corners of the rectangles must be the pillars left on the ground, and two fences can't cross or touch each other." 

To simplify the problem, E-pang Palace can be consider as a plane, and pillars can be considered as points on the plane. The fences you make are rectangles, and you MUST make two rectangles. Please note that the rectangles you make must be parallel to the coordinate axes. 

The figures below shows 3 situations which are not qualified(Thick dots stands for pillars): 


Zhang Liang and Xiao He wanted the total area of their land in E-pang Palace to be maximum. Please bring your computer and go back to Han dynasty to help them so that you may change the history.
 

Input

There are no more than 15 test case. 

For each test case: 

The first line is an integer N, meaning that there are N pillars left in E-pang Palace(4 <=N <= 30). 

Then N lines follow. Each line contains two integers x and y (0 <= x,y <= 200), indicating a pillar's coordinate. No two pillars has the same coordinate. 

The input ends by N = 0.
 

Output

For each test case, print the maximum total area of land Zhang Liang and Xiao He could get. If it was impossible for them to build two qualified fences, print "imp".
 

Sample Input

       
       
8 0 0 1 0 0 1 1 1 0 2 1 2 0 3 1 3 8 0 0 2 0 0 2 2 2 1 2 3 2 1 3 3 3 0
 

Sample Output

       
       
2 imp
 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值