Cod sursa(job #2360232)

Utilizator usureluflorianUsurelu Florian-Robert usureluflorian Data 1 martie 2019 15:03:11
Problema Rubarba Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("rubarba.in");
ofstream g("rubarba.out");
typedef long double ld;
int i,n;
ld x,y,t1x,t2x,t1y,t2y,mij,st,dr=2*atan(1),s,c;
pair<int,int> v[100002];
ld rotim(ld u)
{
    t1x=t1y=1e9;
    t2x=t2y=-1e9;
    for(int i=1;i<=n;++i)
    {
        s=sin(u);
        c=cos(u);
        x=v[i].first*c-v[i].second*s;
        y=v[i].first*s+v[i].second*c;
        t1x=min(t1x,x);
        t2x=max(t2x,x);
        t1y=min(t1y,y);
        t2y=max(t2y,y);
    }
    return (t2x-t1x)*(t2y-t1y);
}

int main()
{
    ios::sync_with_stdio(false);
    f>>n;
    for(int i=1;i<=n;++i) f>>v[i].first>>v[i].second;
    while(dr-st>1e-17)
    {
        mij=(st+dr)/2.0;
        if(rotim(mij+1e-17)<rotim(mij)) st=mij;
        else dr=mij;
    }
    g<<fixed<<setprecision(2)<<rotim(st);
    return 0;
}