记录编号 609615 评测结果 AAAAAAAA
题目名称 圈奶牛 最终得分 100
用户昵称 GravatarLikableP 是否通过 通过
代码语言 C++ 运行时间 0.045 s
提交时间 2025-11-24 11:52:11 内存使用 2.10 MiB
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cmath>

const int MAXN = 1e4 + 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;

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);
  }

  std::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;
  });

  std::sort(node + 2, node + n + 1, [](NODE x, NODE y) {
    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];
  }

  double ans = 0;
  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;
}