Pagini recente » Cod sursa (job #1019209) | Cod sursa (job #2864757) | Cod sursa (job #2038566) | Cod sursa (job #815146) | Cod sursa (job #1695053)
#include <bits/stdc++.h>
#define maxN 100005
#define ll long long
#define e 1e-14
using namespace std;
int n, head, st[maxN], Next[maxN];
bool vis[maxN];
double ans;
struct Point
{
int x, y;
} v[maxN];
int cmp(const Point a, const Point b)
{
if (a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
ll cross_product(Point O, Point A, Point B)
{
return 1LL * (A.x - O.x) * (B.y - O.y) - 1LL * (B.x - O.x) * (A.y - O.y);
}
Point newc(int x, int y)
{
Point ans;
ans.x = v[y].x - v[x].x;
ans.y = v[y].y - v[x].y;
return ans;
}
ll DProd(Point A, Point B)
{
return 1LL * A.x * B.x + 1LL * A.y * B.y;
}
ll CProd(Point A, Point B)
{
return 1LL * A.x * B.y - 1LL * A.y * B.x;
}
double Dist(int x, int y, double m)
{
return fabs((1.0 * v[x].y - v[x].x * m) - (1.0 * v[y].y - v[y].x * m)) / sqrt(m * m + 1);
}
void convex_hull()
{
int i, p;
sort(v + 1, v + n + 1, cmp);
st[1] = 1;
st[2] = 2;
head = 2;
vis[2] = 1;
for (i = 1, p = 1; i > 0; i += (p = (i == n ? -p : p)))
{
if (vis[i])
continue;
while (head >= 2 && cross_product(v[st[head - 1]], v[st[head]], v[i]) <= 0LL)
vis[st[head --]] = 0;
st[++ head] = i;
vis[i] = 1;
}
-- head;
}
void read()
{
int i;
freopen("rubarba.in", "r", stdin);
scanf("%d", &n);
for (i = 1; i <= n; ++ i)
scanf("%d %d", &v[i].x, &v[i].y);
}
void solve()
{
int i, p1, p2, p3;
double Dx, Dy;
convex_hull();
if (head < 3)
return;
for (i = 1; i < head; ++ i)
Next[i] = i + 1;
Next[head] = 1;
p1 = 1;
for (i = 1; i <= head; ++ i)
{
while (DProd(newc(st[i], st[Next[i]]), newc(st[p1], st[Next[p1]])) > 0LL)
p1 = Next[p1];
if (i == 1)
p2 = p1;
while (CProd(newc(st[i], st[Next[i]]), newc(st[p2], st[Next[p2]])) > 0LL)
p2 = Next[p2];
if (i == 1)
p3 = p2;
while (DProd(newc(st[i], st[Next[i]]), newc(st[p3], st[Next[p3]])) < 0LL)
p3 = Next[p3];
if (v[st[i]].x == v[st[Next[i]]].x)
{
Dx = fabs((double)(v[st[i]].x * 1.0 - v[st[p2]].x * 1.0));
Dy = fabs((double)(v[st[p1]].y * 1.0 - v[st[p3]].y * 1.0));
}
else if (v[st[i]].y == v[st[Next[i]]].y)
{
Dx = fabs((double)(v[st[p1]].x * 1.0 - v[st[p3]].x * 1.0));
Dy = fabs((double)(v[st[i]].y * 1.0 - v[st[p2]].y * 1.0));
}
else
{
double m = (double)(1.0 * (v[st[Next[i]]].y - v[st[i]].y) / (v[st[Next[i]]].x - v[st[i]].x));
Dx = Dist(st[i], st[p2], m);
Dy = Dist(st[p1], st[p3], -1.0 / m);
}
if (i == 1)
ans = Dx * Dy;
else if (Dx * Dy < ans)
ans = Dx * Dy;
}
}
void write()
{
freopen("rubarba.out", "w", stdout);
printf("%.2lf\n", ans);
}
int main()
{
read();
solve();
write();
return 0;
}