标签:c++ www main point turn uri http tmp typename
https://www.luogu.org/problemnew/show/P2742
#include <bits/stdc++.h>
#define db double
#define N 10005
using namespace std;
template <typename T> T sqr(T x) {return x * x;}
struct Point {
db x, y;
}p[N], s[N];
db dist(Point p1, Point p2) {
return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y));
}
bool cmp(Point p1, Point p2) {
return (p1.x == p2.x)? (p1.y < p2.y): (p1.x < p2.x);
}
db cross(Point p1, Point p2, Point p3, Point p4) {
return (p2.x - p1.x) * (p4.y - p3.y) - (p4.x - p3.x) * (p2.y - p1.y);
}
int n, tot;
db ans = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i ++) scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p + 1, p + 1 + n, cmp);
tot = 0;
for (int i = 1; i <= n; i ++) {
while (tot > 1 && cross(s[tot], s[tot - 1], s[tot], p[i]) <= 0) -- tot;
s[++ tot] = p[i];
}
int tmp = tot;
for (int i = n - 1; i >= 1; i --) {
while (tot > tmp && cross(s[tot], s[tot - 1], s[tot], p[i]) <= 0) -- tot;
s[++ tot] = p[i];
}
for (int i = 2; i <= tot; i ++) ans += dist(s[i], s[i - 1]);
printf("%.2lf\n", ans);
return 0;
}
标签:c++ www main point turn uri http tmp typename
原文地址:https://www.cnblogs.com/chhokmah/p/10632630.html