WA on #2 91pts 求调
查看原帖
WA on #2 91pts 求调
701302
BLuemoon_楼主2024/1/27 18:51

Code:

// BLuemoon_
#include <bits/stdc++.h>

using namespace std;
using DB = double;

const int kMaxN = 1e5 + 5;

struct Dot {
  DB x, y;
  const DB operator ^(Dot& a) {
    return sqrt((x - a.x) * (x - a.x) + (y - a.y) * (y - a.y));
  }
};

int n, cnt;
DB ans;
Dot a[kMaxN], s[kMaxN];

DB C(Dot s1, Dot f1, Dot s2, Dot f2) {
  return (f1.x - s1.x) * (f2.y - s2.y) - (f2.x - s2.x) * (f1.y - s2.y);
}
bool CMP(Dot l, Dot r) {
  DB k = C(a[1], l, a[1], r);
  return ((k > 0) || (k == 0 && (a[1] ^ l) < (a[1] ^ r)));
}

int main() {
  cin >> n;
  int y = INT_MAX, tmp;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
    if (a[i].y < y) {
      y = a[i].y, tmp = i;
    }
  }
  swap(a[1], a[tmp]);
  sort(a + 2, a + n + 1, CMP);
  s[++cnt] = a[1];
  for (int i = 2; i <= n; i++) {
    for (; cnt > 1 && C(s[cnt - 1], s[cnt], s[cnt - 1], a[i]) <= 0; cnt--) {
    }
    s[++cnt] = a[i];
  }
  s[++cnt] = a[1];
  for (int i = 1; i < cnt; i++) {
    ans += s[i] ^ s[i + 1];
  }
  cout << fixed << setprecision(2) << ans << '\n';
  return 0;
}

已下载数据(#2):

in:
10
5 0
0 0
2 0
6 0
9 0
8 0
1 0
7 0
4 0
3 0
right_out:
18.00
my_out:
10.00
2024/1/27 18:51
加载中...