Advertisement
tepyotin2

Farm Enclosure

Jan 17th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct Points{
  6.     int x;
  7.     int y;
  8.     int idx;
  9.     Points(){};
  10.     Points(int x1, int y1, int idx1){
  11.         x = x1;
  12.         y = y1;
  13.         idx = idx1;
  14.     };
  15. };
  16.  
  17. int n;
  18.  
  19. int sx(Points a, Points b){
  20.     if(a.x != b.x){
  21.         return a.x > b.x;
  22.     }else{
  23.         return a.y > b.y;
  24.     }
  25. }
  26.  
  27. int sy(Points a, Points b){
  28.     if(a.y != b.y){
  29.         return a.y > b.y;
  30.     }else{
  31.         return a.x > b.x;
  32.     }
  33. }
  34.  
  35. int main(){
  36.     ios_base::sync_with_stdio(0), cin.tie(0);
  37.     // freopen("fenclosure.in", "r", stdin);
  38.     cin >> n;
  39.     int a, b;
  40.     int mid_left = n/2;
  41.     // cout << mid_left << '\n';
  42.     int mid_right = mid_left;
  43.     if(n%2 == 1){
  44.         mid_right = mid_left+1;
  45.     }
  46.     // cout << mid_right << '\n';
  47.     Points point[n];
  48.     for(int i=0; i<n; i++){
  49.         cin >> a >> b;
  50.         point[i].x = a;
  51.         point[i].y = b;
  52.         point[i].idx = i+1;
  53.     }
  54.     sort(point, point+n, sx);
  55.     for(int i=0; i<n; i++){
  56.         // cout << "i: " << i << ", pos: " << point[i].idx << ", x: " << point[i].x << ", y: " << point[i].y << '\n';
  57.     }
  58.     int one = 0;
  59.     int two = 0;
  60.     int three = 0;
  61.     int four = 0;
  62.     int val = 0;
  63.     int mid_left1 = mid_left;
  64.     int mid_left2 = mid_left;
  65.     int mid_right1 = mid_right;
  66.     int mid_right2 = mid_right;
  67.     vector<Points> mx_x;
  68.     mx_x.push_back(Points(point[0].x, point[0].y, point[0].idx));
  69.     one++;
  70.     // cout << mx_x[0].x << ", " << mx_x[0].y << '\n';
  71.     for(int i=1; i<mid_left1; i++){
  72.         if(val >= 3 && point[i].x != point[0].x){
  73.             // cout << "val: " << val << ", point[i].x: " << point[i].x << ", point[0].x: " << point[0].x << '\n';
  74.             break;
  75.         }
  76.         if(val>=3 && point[i].x == point[0].x){
  77.             mid_left1++;
  78.         }
  79.         val++;
  80.         one++;
  81.         mx_x.push_back(Points(point[i].x, point[i].y, point[i].idx));
  82.         // cout << "mx_x[i].x: " << mx_x[i].x << ", mx_x[i].y: " << mx_x[i].y << '\n';
  83.     }
  84.     val = 0;
  85.     int val_2 = 0;
  86.     vector<Points> mn_x;
  87.     mn_x.push_back(Points(point[n-1].x, point[n-1].y, point[n-1].idx));
  88.     two++;
  89.     // cout << mn_x[0].x << ", " << mn_x[0].y << '\n';
  90.     for(int i=n-2; i>=mid_right1; i--){
  91.         if(val >= 3 && point[i].x != point[n-1].x){
  92.             break;
  93.         }
  94.         if(val>=3 && point[i].x == point[n-1].x){
  95.             mid_right1--;
  96.         }
  97.         val++;
  98.         two++;
  99.         mn_x.push_back(Points(point[i].x, point[i].y, point[i].idx));
  100.         // cout << "i: " << i << ", mn_x[i].x: " << mn_x[val_2].x << ", mn_x[i].y: " << mn_x[val_2].y << '\n';
  101.         val_2++;
  102.     }
  103.     val = 0;
  104.     sort(point, point+n, sy);
  105.     vector<Points> mx_y;
  106.     mx_y.push_back(Points(point[0].x, point[0].y, point[0].idx));
  107.     three++;
  108.     // cout << mx_y[0].x << ", " << mx_y[0].y << '\n';
  109.     for(int i=1; i<mid_left2; i++){
  110.         if(val >= 3 && point[i].y != point[0].y){
  111.             break;
  112.         }
  113.         if(val>=3 && point[i].y == point[0].y){
  114.             mid_left2++;
  115.         }
  116.         val++;
  117.         three++;
  118.         mx_y.push_back(Points(point[i].x, point[i].y, point[i].idx));
  119.         // cout << "mx_y[i].x: " << mx_y[i].x << ", mx_y[i].y: " << mx_y[i].y << '\n';
  120.     }
  121.     val = 0;
  122.     val_2 = 0;
  123.     vector<Points> mn_y;
  124.     mn_y.push_back(Points(point[n-1].x, point[n-1].y, point[n-1].idx));
  125.     four++;
  126.     // cout << mn_y[0].x << ", " << mn_y[0].y << '\n';
  127.     for(int i=n-2; i>=mid_right2; i--){
  128.         if(val >= 3 && point[i].y != point[n-1].y){
  129.             break;
  130.         }
  131.         if(val>=3 && point[i].y == point[n-1].y){
  132.             mid_right2++;
  133.         }
  134.         val++;
  135.         four++;
  136.         mn_y.push_back(Points(point[i].x, point[i].y, point[i].idx));
  137.         // cout << "mn_y[i].x: " << mn_y[val_2].x << ", mn_y[i].y: " << mn_y[val_2].y << '\n';
  138.         val_2++;
  139.     }
  140.     // cout << "one: " << one << '\n';
  141.     // cout << "two: " << two << '\n';
  142.     // cout << "three: " << three << '\n';
  143.     // cout << "four: " << four << '\n';
  144.     int count = 0;
  145.     int area = 0;
  146.     int ans = INT_MAX;
  147.     for(int a=0; a<one; a++){
  148.         for(int b=0; b<two; b++){
  149.             for(int c=0; c<three; c++){
  150.                 for(int d=0; d<four; d++){
  151.                     count = 0;
  152.                     for(int i=0; i<n; i++){
  153.                         if(point[i].x > mx_x[a].x || point[i].x < mn_x[b].x || point[i].y > mx_y[c].y || point[i].y < mn_y[d].y){
  154.                             count++;
  155.                         }
  156.                     }
  157.                     // cout << "count: " << count << '\n';
  158.                     if(count<=3){
  159.                         area = (mx_x[a].x - mn_x[b].x) * (mx_y[c].y - mn_y[d].y);
  160.                         // cout << "area: " << area << ", mx_x: " << mx_x[a].x << ", mn_x: " << mn_x[b].x << ", mx_y: " << mx_y[c].y << ", mn_y: " << mn_y[d].y << '\n';
  161.                         ans = min(area, ans);
  162.                     }
  163.                 }
  164.             }
  165.         }
  166.     }
  167.     cout << ans << '\n';
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement