LA 4728 对踵点对

#include <bits/stdc++.h>
using namespace std;
struct Point
{
	double x, y;
	Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector;
int Cross(Vector A, Vector B)
{
	return A.x * B.y - A.y * B.x;
}
Vector operator +(Vector A, Vector B)//
{
	return Vector(A.x + B.x, A.y + B.y);
}
Vector operator -(Point A, Point B)//
{
	return Vector(A.x - B.x , A.y - B.y);
}
Vector operator *(Vector A, double p)//
{
	return Vector(A.x * p, A.y * p);
}
Vector operator /(Vector A, double p)//
{
	return Vector(A.x / p, A.y / p);
}
bool operator <(const Point &a, const Point &b)//
{
	return a.x < b.x || (a.x == b.x && a.y < b.y);
}
const double eps = 1e-10;
int dcmp(double x)//
{
	if (fabs(x) < eps) return 0;
	else return x < 0 ? -1 : 1;
}
bool operator ==(const Point &a, const Point &b)//
{
	return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Vector A, Vector B)//
{
	return A.x * B.x + A.y * B.y;
}
int Dist2(const Point &A, const Point &B)
{
	return (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
}
vector<Point> ConvexHull(vector<Point>& p)
{
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());

	int n = p.size();
	int m = 0;
	vector<Point> ch(n + 1);
	for (int i = 0; i < n; i++)
	{
		while (m > 1 && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m--;
		ch[m++] = p[i];
	}
	int k = m;
	for (int i = n - 2; i >= 0; i--)
	{
		while (m > k && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m--;
		ch[m++] = p[i];
	}
	if (n > 1) m--;
	ch.resize(m);
	return ch;
}
int getMaxDirmater(vector<Point>&points)
{
	vector<Point>p = ConvexHull(points);
	int n = p.size();
	if (n == 1) return 0;
	if (n == 2) return Dist2(p[0], p[1]);
	p.push_back(p[0]);
	int ans = 0;
	for (int u = 0, v = 1; u < n; u++)
	{
		for (;;)
		{
			int diff = Cross(p[u + 1] - p[u], p[v + 1] - p[v]);
			if (diff <= 0)
			{
				ans = max(ans, Dist2(p[u], p[v]));
				if (diff == 0) ans = max(ans, Dist2(p[u], p[v + 1]));
				break;
			}
			v = (v + 1) % n;
		}
	}
	return ans;
}
int T, n, kase, x, y, z;
int main(int argc, char const *argv[])
{
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		vector<Point>points;
		for (int i = 0; i < n; i++)
		{
			scanf("%d%d%d", &x, &y, &z);
			points.push_back(Point(x, y));
			points.push_back(Point(x + z, y));
			points.push_back(Point(x, y + z));
			points.push_back(Point(x + z, y + z));
		}
		printf("%d\n", getMaxDirmater(points));
	}
	return 0;
}


有n个正方形,给出了左下角坐标和边长,问在他们的顶点中距离最大的两个点的距离的平方。 


有特定的方法处理这种对踵点对的问题:旋转卡壳

http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html

这个网址上讲得非常好。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值