记录编号 600795 评测结果 AAAAAAAA
题目名称 圈奶牛 最终得分 100
用户昵称 GravatarLikableP 是否通过 通过
代码语言 C++ 运行时间 0.044 s
提交时间 2025-05-15 21:34:28 内存使用 2.11 MiB
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cmath>
using ::std::sort;
using ::std::pow;
using ::std::sqrt;

const int MAXN = 1e5 + 10; 

struct NODE {
	double x, y;
} node[MAXN]; 

bool check(NODE a1, NODE a2, NODE b1, NODE b2) {
	return (a1.y - a2.y) * (b1.x - b2.x) <= (b1.y - b2.y) * (a1.x - a2.x);
}  

double dis(NODE x, NODE y) {
	return sqrt(pow(x.x - y.x, 2) + pow(x.y - y.y, 2));
} 

int n;
NODE sta[MAXN];
int top; 
double ans;

int main() {
	freopen("fc.in", "r", stdin);
	freopen("fc.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lf %lf", &node[i].x, &node[i].y);
	}
	
	sort(node + 1, node + n + 1, [](NODE x, NODE y) {
		if (x.x != y.x) return x.x < y.x;
		return x.y > y.y;
	}); 
	
	sort(node + 2, node + n + 1, [](NODE x, NODE y) {
		if (x.x == node[1].x && y.x == node[1].x) return x.y > y.y; 
		if (x.y == node[1].y && y.y == node[1].y) return x.x < y.x;
		return !check(x, node[1], y, node[1]);
	});
	
	sta[++top] = node[1];
	for (int i = 2; i <= n; ++i) {
		while (top > 1 && !check(node[i], sta[top], sta[top], sta[top - 1])) top--;
		sta[++top] = node[i];
	}
	
	for (int i = 2; i <= top; ++i) {
		ans += dis(sta[i], sta[i - 1]); 
	}
	ans += dis(sta[top], sta[1]);
	
	printf("%.2lf\n", ans);
	return 0;
}