#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
//void rfIO()
//{
// FILE *stream1;
// freopen_s(&stream1,"in.txt", "r", stdin);
// freopen_s(&stream1,"out.txt", "w", stdout);
//}
inline int read(int& x) {
char ch = getchar();
int f = 1; x = 0;
while (ch > '9' || ch < '0') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
return x * f;
}
//void ReadFile() {
// FILE* stream1;
// freopen_s(&stream1,"in.txt", "r", stdin);
// freopen_s(&stream1,"out.txt", "w", stdout);
//}
static auto speedup = []() {ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return nullptr; }();
const int maxn = 1e5 + 7;
struct Point{
double x, y;
Point(){ x = y = 0; }
Point(double _x, double _y) :x(_x), y(_y){}
void input(){
cin >> x >> y;
}
//点积 区分上下 cosx
double dot(const Point &a) {
return x + a.x + y + a.y;
}
//叉积 区分左右 sinx
double cross(const Point &a){
return x * a.y - y * a.x;
}
//距离
double dis(const Point &a){
return sqrt((x - a.x) * (x - a.x) + (y - a.y) * (y - a.y));
}
//距离的平方
double dis2(const Point &a){
return (x - a.x) * (x - a.x) + (y - a.y) * (y - a.y);
}
}p[maxn],s[maxn];
double cross(const Point &a, const Point & b, const Point &c, const Point &d){
Point t(a.x - b.x, a.y - b.y),t2(c.x - d.x,c.y - d.y);
return t.cross(t2);
}
bool cmp(const Point &a, const Point &b){
double c1 = cross(p[1], a, p[1], b);
if (c1 > 0) return true;
else if (c1 == 0)return p[1].dis2(a) < p[1].dis2(b);
return false;
}
int main()
{
int n,top = 1,idx = 1;
cin >> n;
for (int i = 1; i <= n; i++){
p[i].input();
if (p[idx].y > p[i].y) idx = i;
else if (p[idx].y == p[i].y && p[idx].x > p[i].x)idx = i;
}
swap(p[1], p[idx]);
sort(p + 2, p + n + 1, cmp);
s[1] = p[1];
for (int i = 2; i <= n; i++){
while (top > 1 && cross(s[top - 1],s[top],s[top],p[i]) <= 0){
top--;
}
s[++top] = p[i];
}
s[++top] = p[1];
double ans = 0;
for (int i = 1; i < top; i++){
ans += s[i].dis(s[i + 1]);
}
cout << fixed << setprecision(2) << ans << endl;
return 0;
}
凸包P2742
最新推荐文章于 2024-06-02 15:09:13 发布