Pagini recente » Cod sursa (job #628197) | Cod sursa (job #2484235) | Cod sursa (job #72093) | Cod sursa (job #237544) | Cod sursa (job #2870821)
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#define NMAX 100005
using namespace std;
ifstream fin("rubarba.in");
ofstream fout("rubarba.out");
typedef long double ld;
const ld EPS = 1e-17;
struct pct {
ld x, y;
} a[NMAX];
int n;
inline ld vabs(const ld X) {
return X > 0 ? X : -X;
}
inline bool isEqual(const ld X, const ld Y) {
return vabs(X - Y) <= EPS;
}
inline ld calcArea(const ld ang) {
ld minx = 1e18, maxx = -1e18, miny = 1e18, maxy = -1e18;
const ld sn = sin(ang), cs = cos(ang);
for(int i = 1; i <= n; ++i) {
const pct rotated = {a[i].x * cs - a[i].y * sn,
a[i].x * sn + a[i].y * cs};
if(i == 1) {
minx = maxx = rotated.x;
miny = maxy = rotated.y;
} else {
minx = min(minx, rotated.x);
maxx = max(maxx, rotated.x);
miny = min(miny, rotated.y);
maxy = max(maxy, rotated.y);
}
}
return (maxx - minx) * (maxy - miny);
}
ld cbMaxArea() {
ld st = 0, dr = M_PI / 2, mij;
while(!isEqual(st, dr)) {
mij = (st + dr) / 2;
if(calcArea(mij) < calcArea(mij + EPS))
dr = mij;
else st = mij;
}
return calcArea(st);
}
int main()
{
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> a[i].x >> a[i].y;
fout << fixed << setprecision(7) << cbMaxArea();
return 0;
}