uva_1312_Cricket Field

#include<iostream>      
#include<sstream>      
#include<string>      
#include<vector>      
#include<list>      
#include<set>      
#include<map>    
#include<stack>      
#include<queue>      
#include<algorithm>      
#include<numeric>      
#include<cmath>    
#include<cstdio>    
#include<cstdlib>    
#include<cstring>    
#pragma warning(disable:4996)   
using namespace std;
class Rectangle
{
public:
	int x1, y1;//矩形的左下角坐标
	int x2, y2;//矩形的右上角坐标
	Rectangle(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0)
	{
		x1 = X1, y1 = Y1, x2 = X2, y2 = Y2;
	}
	bool isInRec(const int &X,const int &Y)
	{
		if (X > x1&&X<x2&&Y>y1&&Y < y2)
		{
			return true;
		}
		return false;
	}
};
int main()
{
	//freopen("input.txt", "r", stdin);    
	//freopen("output.txt", "w", stdout);
	int T; cin >> T;
	while (T--)
	{
		int W, H, n; cin >> n >> W >> H;
		vector<Rectangle>rec; rec.push_back({0,0,W,H});
		vector<bool>visited; visited.push_back(false);
		while (n--)
		{
			int x, y; cin >> x >> y;
			for (size_t i = 0, size = rec.size();i!=size;i++)
			{
				//如果该点在矩形内部
				if (!visited[i]&&rec[i].isInRec(x, y))
				{
					auto x1 = rec[i].x1, x2 = rec[i].x2, y1 = rec[i].y1, y2 = rec[i].y2;
					visited[i] = true;
					rec.push_back({x1,y1,x,y2});//左
					visited.push_back(false);
					rec.push_back({x,y1,x2,y2});//右
					visited.push_back(false);
					rec.push_back({ x1,y,x2,y2 });//上
					visited.push_back(false);
					rec.push_back({x1,y1,x2,y});//下
					visited.push_back(false);
				}
			}
		}
		int ans = 0; Rectangle square;
		for (size_t i = 0; i != rec.size(); i++)
		{
			if (!visited[i]&&min(rec[i].x2 - rec[i].x1, rec[i].y2 - rec[i].y1) > ans)
			{
				ans = min(rec[i].x2 - rec[i].x1, rec[i].y2 - rec[i].y1);
				square = rec[i];
			}
		}
		cout << square.x1 << ' ' << square.y1 << ' ' << ans << endl;
		if (T)
		{
			cout << endl;
		}
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值