HDU5128The E-pang Palace(计算几何暴力枚举)

127 篇文章 0 订阅
36 篇文章 0 订阅

The E-pang Palace

题解:预处理出所有矩形,然后枚举满足情况的两两矩形即可。因为是矩形,所以我们只需要存对角的两个点即可。就是要注意嵌套也是满足的。

代码

#include<bits/stdc++.h>

using namespace std;

struct Point{
	int x,y;
	Point() {}
	Point(int _x,int _y) { x = _x, y = _y; }
	bool operator < (const Point & u)const{
		if(x == u.x) return y < u.y;
		return x < u.x;
	}
};

struct rectangle{
	Point p1,p2;
	int area;
};

bool vis[301][301];

int ok(rectangle a, rectangle b)
{
	if(a.p2.x < b.p1.x || a.p2.y < b.p1.y)
		return 1;
	if(b.p2.x < a.p1.x || b.p2.y < a.p1.y)
		return 1;
	if(a.p1.x < b.p1.x && a.p1.y < b.p1.y && a.p2.x > b.p2.x && a.p2.y > b.p2.y)
		return 2;
	if(b.p1.x < a.p1.x && b.p1.y < a.p1.y && b.p2.x > a.p2.x && b.p2.y > a.p2.y)
		return 3;
	return 0;
		
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
	int n;
	while(cin>>n && n){
		vector<Point> point;
		int x,y;
		memset(vis, 0, sizeof vis);
		for(int i = 0; i < n; ++i){
			cin>>x>>y;
			vis[x][y] = 1;
			point.push_back(Point{x,y});
		}
		sort(point.begin(), point.end());
		vector<rectangle> rec;
		for(int i = 0; i < point.size(); ++i){
			for(int j = i + 1; j < point.size(); ++j){
				int px = point[j].x, py = point[i].y;
				if(px > point[i].x && point[j].y > py && vis[px][py] && vis[point[i].x][point[j].y]){
					Point t1 = {point[i].x, point[i].y};
					Point t2 = {point[j].x, point[j].y};
					int area = (point[j].x - point[i].x) * (point[j].y - point[i].y);
					rec.push_back(rectangle{t1,t2,area});
				}
			}
		}
		int ans = -1;
		for(int i = 0; i < rec.size(); ++i){
			for(int j = i + 1; j < rec.size(); ++j){
				if(ok(rec[i],rec[j]) == 1)
					ans = max(ans, rec[i].area + rec[j].area);
				else if(ok(rec[i],rec[j]) == 2)
					ans = max(ans, rec[i].area);
				else if(ok(rec[i],rec[j]) == 3) 
					ans = max(ans, rec[j].area);
			}	
		}
		if(~ans) cout<<ans<<endl;
		else cout<<"imp"<<endl;
	}
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值