Cricket Field poj 2173

这题总矩形很大,但是障碍点数量很小,以为每个小矩形的边必定过一点或者是大矩形边界,所以可以按照点暴力搞,再把矩形的宽作为边长,复杂度应该是O(n^3),图省事写了个O(n^3logn)的。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;

const int INFI((INT_MAX-1) >> 1);

int x[110], y[110];
int ax[110];
int ta[110];

int main()
{
	int w, h, n;
	while(~scanf("%d%d%d", &n, &w, &h))
	{
		int tn = 0;
		for(int i = 1; i <= n; ++i)
		{
			scanf("%d%d", x+i, y+i);
			ax[++tn] = x[i];
		}
		ax[++tn] = 0;
		ax[++tn] = w;
		sort(ax+1, ax+1+tn);
		ax[0] = -1;
		int count = 0;
		for(int i = 1; i <= tn; ++i)
			if(ax[i] != ax[i-1])
				ax[++count] = ax[i];
		int ans = 0;
		int gx = 0, gy = 0;
		for(int i = 1; i <= count; ++i)
			for(int j = i+1; j <= count; ++j)
			{
				ta[1] = 0;
				ta[2] = h;
				int tc = 2;
				for(int k = 1; k <= tn; ++k)
					if(x[k] > ax[i] && x[k] < ax[j])
						ta[++tc] = y[k];
				sort(ta+1, ta+1+tc);
				int mx = 0;
				int ty1, ty2;
				for(int k = 2; k <= tc; ++k)
				{
					int temp = ta[k]-ta[k-1];
					if(temp > mx)
					{
						mx = temp;
						ty1 = ta[k-1];
						ty2 = ta[k];
					}
				}
				int temp = min(ax[j]-ax[i], mx);
				if(temp > ans)
				{
					ans = temp;
					gx = ax[i];
					gy = ty1;
				}
			}
		printf("%d %d %d\n", gx, gy, ans);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值