1、POJ 2187 Beauty Contest
题意:
求最远点对距离的平方
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <cassert>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
struct Point { double x, y; Point(double x = 0.0, double y = 0.0):x(x),y(y){} };
struct Seg { Point a, b; };
typedef Point Vector;
typedef Seg Line;
struct Circle {
Point c; double r;
Point point(double a) { return Point{c.x + cos(a) * r, c.y + sin(a) * r}; }
};
typedef long long ll;
const double INF = 1e20;
const double eps = 1e-10;
const double PI = acos(-1.0);
const int maxn = 5e4 + 10;
Point point[maxn], ans[maxn];
int N;
Point operator + (const Point& a, const Vector& b) { return Point(a.x + b.x, a.y + b.y); }
Vector operator - (const Point& a, const Point& b) { return Vector(a.x - b.x, a.y - b.y); }
Vector operator * (const Vector& a, double k) { return Vector(a.x * k, a.y * k); }
Vector operator / (const Vector& a, double k) { return Vector{a.x / k, a.y / k}; }
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;
}
bool operator < (const Point& a, const Point& b) {
int t1 = dcmp(a.x - b.x), t2 = dcmp(a.y - b.y); return t1 < 0 || (t1 == 0 && t2 < 0);
}
Point read_point() { double x, y; scanf("%lf %lf", &x, &y); return Point{x, y}; }
Seg read_seg() { return Seg{read_point(), read_point()}; }
Line read_line() { return Line{read_point(), read_point()}; }
double dot(const Vector& a, const Vector& b) { return a.x * b.x + a.y * b.y; }
double cross(const Vector& a, const Vector& b) { return a.x * b.y - a.y * b.x; }
double length(const Vector& a) { return dot(a, a); }
int convex_hull(Point* p, int n, Point* ch) {
sort(p, p + n); int m = 0;
REP(i, n) {
while (m > 1 && dcmp(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 && dcmp(cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0) { --m; }
ch[m++] = p[i];
}
if (n > 1) { --m; }
return m;
}
double poly_area(Point* p, int n) {
double area = 0.0;
for (int i = 1; i < n - 1; ++i) { area += cross(p[i] - p[0], p[i + 1] - p[0]); }
return area / 2.0;
}
bool is_parallel(const Seg& p, const Seg& q) {
double t = (p.a.y - p.b.y) * (q.a.x - q.b.x) - (p.a.x - p.b.x) * (q.a.y - q.b.y);
return dcmp(t) == 0;
}
int main() {
#ifdef __AiR_H
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif // __AiR_H
scanf("%d", &N);
REP(i, N) { point[i] = read_point(); }
int num = convex_hull(point, N, ans);
double Max = 0.0;
REP(i, num - 1) for (int j = i + 1; j < num; ++j) {
Max = max(Max, length(ans[j] - ans[i]));
}
printf("%.0f\n", Max);
#ifdef __AiR_H
printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
return 0;
}