QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768287 | #9520. Concave Hull | DopplerXD | WA | 2ms | 10028kb | C++20 | 3.9kb | 2024-11-21 08:41:32 | 2024-11-21 08:41:33 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const double pi = acos(-1.0);
const double eps = 1e-8;
// 判断 x 的大小,<0 返回 -1,>0 返回 1,==0 返回 0
int sgn(double x) {
if (fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
// 比较两个浮点数
int dcmp(double x, double y) {
if (fabs(x - y) < eps) return 0;
else return x < y ? -1 : 1;
}
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator + (const Point& B) const { return Point(x + B.x, y + B.y); }
Point operator - (const Point& B) const { return Point(x - B.x, y - B.y); }
Point operator * (double k) const { return Point(x * k, y * k); }
Point operator / (double k) const { return Point(x / k, y / k); }
bool operator == (const Point& B) const {
return sgn(x - B.x) == 0 && sgn(y - B.y) == 0;
}
bool operator < (const Point& B) const {
return sgn(x - B.x) < 0 || sgn(x - B.x) == 0 && sgn(y - B.y) < 0;
}
};
typedef Point Vector;
class Geometry {
public:
static double Distance(const Point& A, const Point& B) {
return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}
static double Dot(const Vector& A, const Vector& B) {
return A.x * B.x + A.y * B.y;
}
static double Cross(const Vector& A, const Vector& B) {
return A.x * B.y - A.y * B.x;
}
static double Area2(const Point& A, const Point& B, const Point& C) {
return Cross(B - A, C - A);
}
};
class PolygonOps {
public:
static double Area(int n, Point* ch) {
double area = 0;
for (int i = 0; i < n; i++)
area += Geometry::Cross(ch[i], ch[(i + 1) % n]);
return area;
}
};
int Convex_hull(Point* p, int n, Point* ch) {
sort(p, p + n);
int v = 0;
for (int i = 0; i < n; i++) {
while (v > 1 && sgn(Geometry::Cross(ch[v - 1] - ch[v - 2], p[i] - ch[v - 1])) <= 0) {
v--;
}
ch[v++] = p[i];
}
int j = v;
for (int i = n - 1; i >= 0; i--) {
while (v > j && sgn(Geometry::Cross(ch[v - 1] - ch[v - 2], p[i] - ch[v - 1])) <= 0) {
v--;
}
ch[v++] = p[i];
}
if (n > 1) v--;
return v;
}
int n, n_left, m;
Point p[N], Left[N];
Point ch[N], chL[N], ch_sorted[N];
void solve() {
cin >> n;
n_left = m = 0;
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
int v = Convex_hull(p, n, ch);
set<Point> st;
for (int i = 0; i < v; i++) {
st.emplace(ch[i]);
}
for (int i = 0; i < n; i++) {
if (!st.count(p[i])) {
Left[n_left++] = p[i];
}
}
int vL = Convex_hull(Left, n_left, chL);
if (vL == 0) {
cout << -1 << '\n';
return;
}
// cerr << "v: " << v << '\n';
// cerr << "vL: " << vL << ", n_left: " << n_left << '\n';
ll area = PolygonOps::Area(v, ch);
ll ans = 0;
ch[v] = ch[0];
chL[vL] = chL[0];
// for (int i = 0, j = 0; i < v; i++) {
// ll tri_0, tri_1;
// int cnt = 0;
// while (cnt < v &&
// (tri_0 = Geometry::Area2(chL[j], ch[i], ch[i + 1])) >=
// (tri_1 = Geometry::Area2(chL[j + 1], ch[i], ch[i + 1]))) {
// j = (j + 1) % vL;
// cnt++;
// }
// ans = std::max(ans, area - tri_0);
// }
for (int i = 0; i < v; i++) {
for (int j = 0; j < vL; j++) {
ll tri = Geometry::Area2(chL[j], ch[i], ch[i + 1]);
ans = std::max(ans, area - tri);
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int _T = 1;
cin >> _T;
while (_T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9812kb
input:
2 6 -2 0 1 -2 5 2 0 4 1 2 3 1 4 0 0 1 0 0 1 1 1
output:
40 -1
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 10028kb
input:
10 243 -494423502 -591557038 -493438474 -648991734 -493289308 -656152126 -491185085 -661710614 -489063449 -666925265 -464265894 -709944049 -447472922 -737242534 -415977509 -773788538 -394263365 -797285016 -382728841 -807396819 -373481975 -814685302 -368242265 -818267002 -344482838 -833805545 -279398...
output:
2178418010787348230 1826413114144932690 1651687576234219782 1883871859778998720 2119126281997959888 894016174881844671 2271191316922159432 1998643358049669130 1740474221286618400 1168195646932543184
result:
wrong answer 1st lines differ - expected: '2178418010787347715', found: '2178418010787348230'