您的位置:首页 > 其它

LA 4728 对踵点对

2016-03-02 20:55 288 查看
#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
这个网址上讲得非常好。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: