Cod sursa(job #2627111)

Utilizator drknss_Hehe hehe drknss_ Data 9 iunie 2020 20:12:39
Problema Rubarba Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.68 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 1e6 + 11;
const int NMAX = 1e4 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);


ifstream in("rubarba.in");
ofstream out("rubarba.out");

int n;
double x[N], y[N];

double area(double A){

    long double minX = INF64, maxX = -INF64;
    long double minY = INF64, maxY = -INF64;

    double cs = cos(A);
    double sn = sin(A);

    for(int i = 1; i <= n; i++){

        long double X = x[i]*cs - y[i]*sn;
        long double Y = x[i]*sn + y[i]*cs;

        minX = min(minX, X);
        maxX = max(maxX, X);

        minY = min(minY, Y);
        maxY = max(maxY, Y);
    }

    return (maxX - minX)*(maxY- minY);
}

double ternary_search(double l, double r){

    if(r - l < eps)return l;

    double t1 = l + (r - l)/3;
    double t2 = r - (r - l)/3;

    if(area(t1) < area(t2))return ternary_search(l, t2);
    return ternary_search(t1, r);
}


int solve(){

    out << setprecision(2) << fixed;

    in >> n;

    for(int i = 1; i <= n; i++){
        in >> x[i] >> y[i];
    }

    out << area(ternary_search(0,PI/2));
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    int t = 1;

    //cin >> t;

    while(t--){

        solve();

    }

}