Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <memory.h>
- #include <cstdio>
- #include <cmath>
- #include <map>
- #include <queue>
- #include <unordered_map>
- using namespace std;
- typedef long long ll;
- const int mod = 1e9 + 9;
- const ll inf = 4e18;
- const int N = 200005;
- struct pt {
- double x, y;
- };
- bool cmp (pt a, pt b) {
- return a.x < b.x || a.x == b.x && a.y < b.y;
- }
- bool cw (pt a, pt b, pt c) {
- return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y) < 0;
- }
- bool ccw (pt a, pt b, pt c) {
- return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y) > 0;
- }
- void convex_hull (vector<pt> & a) {
- if (a.size() == 1) return;
- sort (a.begin(), a.end(), &cmp);
- pt p1 = a[0], p2 = a.back();
- vector<pt> up, down;
- up.push_back (p1);
- down.push_back (p1);
- for (size_t i=1; i<a.size(); ++i) {
- if (i==a.size()-1 || cw (p1, a[i], p2)) {
- while (up.size()>=2 && !cw (up[up.size()-2], up[up.size()-1], a[i]))
- up.pop_back();
- up.push_back (a[i]);
- }
- if (i==a.size()-1 || ccw (p1, a[i], p2)) {
- while (down.size()>=2 && !ccw (down[down.size()-2], down[down.size()-1], a[i]))
- down.pop_back();
- down.push_back (a[i]);
- }
- }
- a.clear();
- for (size_t i=0; i<up.size(); ++i)
- a.push_back (up[i]);
- for (size_t i=down.size()-2; i>0; --i)
- a.push_back (down[i]);
- }
- vector <pt> hull;
- int n;
- double dist_v(double a, double b, double c, int i){
- double numerator = a * hull[i].x + b * hull[i].y + c;
- double denominator = sqrt(a * a + b * b);
- return fabs(numerator / denominator);
- }
- double dist_h(double x, double y, int i){
- pt a, b;
- b.x = x;
- b.y = y;
- a.x = hull[i].x;
- a.y = hull[i].y;
- double projection = (a.x * b.x + a.y * b.y) / sqrt(b.x * b.x + b.y * b.y);
- return projection;
- }
- int main(){
- cin >> n;
- for(int i = 0; i < n; ++i){
- double x, y;
- cin >> x >> y;
- hull.push_back({x, y});
- }
- convex_hull(hull);
- int n = (int)hull.size();
- for(int i = 0; i < n; ++i){
- hull.push_back(hull[i]);
- }
- double main_ans = inf;
- int l, r;
- for(int i = 0; i < n; ++i){
- double x = hull[i + 1].x - hull[i].x;
- double y = hull[i + 1].y - hull[i].y;
- double a = hull[i].y - hull[i + 1].y;
- double b = hull[i + 1].x - hull[i].x;
- double c = -a * hull[i].x - b * hull[i].y;
- l = i + 1;
- r = i + n;
- while(r - l >= 3){
- double m1 = l + (r - l) / 3,
- m2 = r - (r - l) / 3;
- if (dist_v(a, b, c, m1) < dist_v(a, b, c, m2))
- l = m1;
- else
- r = m2;
- }
- double dist_vertical = dist_v(a, b, c, l);
- for(int it = l + 1; it <= r; ++it){
- dist_vertical = max(dist_vertical, dist_v(a, b, c, it));
- }
- l = i + 1;
- r = i + n;
- while(r - l >= 3){
- double m1 = l + (r - l) / 3,
- m2 = r - (r - l) / 3;
- if (dist_h(x, y , m1) < dist_h(x, y, m2))
- l = m1;
- else
- r = m2;
- }
- double mx = dist_h(x, y, l);
- for(int it = l + 1; it <= r; ++it){
- mx = max(mx, dist_h(x, y, it));
- }
- l = i + 1;
- r = i + n;
- while(r - l >= 3){
- double m1 = l + (r - l) / 3,
- m2 = r - (r - l) / 3;
- if (dist_h(x, y , m1) > dist_h(x, y, m2))
- l = m1;
- else
- r = m2;
- }
- double mn = dist_h(x, y, l);
- for(int it = l + 1; it <= r; ++it){
- mn = min(mn, dist_h(x, y, it));
- }
- double dist_horizontal = mx - mn;
- main_ans = min(main_ans, dist_horizontal * dist_vertical);
- }
- cout << (ll)(main_ans + 0.5) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement