Advertisement
tepyotin2

Untitled

Jul 8th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. /*
  5.  problem1: must find all xn = min(min(min(b.first, c.first), d.first), e.first) instead of xn = b.first; ...
  6.  problem2: use    pair<int, int> c/e = listX[n - 1 - j] instead of  listX[listX.size() - 1 - j]; so get 0,0 over array
  7.  problem3: forgot to valid same border
  8.  *  no >> if ( xn <  pv.first  && pv.first < xx
  9.                 && yn < pv.second && pv.second < yx)
  10.             {
  11.         ok >> if ( xn <  pv.first  && pv.first < xx
  12.                 && yn < pv.second && pv.second < yx)
  13.             {
  14.  */
  15. bool isDiag = false;
  16. vector<pair<int, int>> listV ;
  17. int B = 4;
  18. bool comp( pair<int, int>& a, pair<int, int>& b)
  19. {
  20.      if ( a.second == b.second)
  21.      {
  22.         return a.first > b.first;
  23.      }
  24.      return a.second < b.second;
  25. }
  26. bool same(pair<int, int>& a, pair<int, int>& b){
  27.     return (a.first == b.first && a.second == b.second);
  28. }
  29. bool samePoint(pair<int, int>& a, pair<int, int>& b, pair<int, int>& c, pair<int, int>& d, pair<int, int>& e){
  30.     return same(a, b) || same(a, c) || same(a, d) || same(a, e);
  31.        
  32.     //return (a.first == b.first && a.second == b.second)
  33.             //|| (a.first == c.first && a.second == c.second)
  34.             //|| (a.first == d.first && a.second == d.second)
  35.             //|| (a.first == e.first && a.second == e.second)
  36.                 ;
  37. }
  38. int main(){
  39.     //isDiag = true;
  40.     freopen("reduce.in", "r", stdin);
  41.     //freopen("reduce_silver_open16/2.in", "r", stdin);
  42.     int n;
  43.     cin >> n;
  44.    
  45.     int x, y;
  46.     if(isDiag) cout << "n: " << n << endl;
  47.     for (int i = 0; i < n; i++)
  48.     {
  49.         cin >> x >> y;
  50.         listV.push_back({x, y});
  51.     }
  52.    
  53.     sort(listV.begin(), listV.end());
  54.     vector<pair<int, int>> listX ;
  55.     vector<pair<int, int>> listY ;
  56.    
  57.    
  58.     //int loop = 0;
  59.     //pair<int, int> lastP = listV[0];
  60.     //for (int i = 1; i < n; i++)
  61.     //{
  62.         //pair<int, int> p = listV[i];
  63.         //if(p.first != lastP.first && p.second != lastP.second){
  64.             //listX.push_back(lastP);
  65.             //lastP = p;
  66.             //loop++;
  67.             //if (loop == B)
  68.             //{
  69.                 //break;
  70.             //}
  71.         //}
  72.     //}
  73.     //loop = 0;
  74.     //lastP = listV[n-1];
  75.     //for (int i = 1; i < n; i++)
  76.     //{
  77.         //pair<int, int> p = listV[n-1-i];
  78.         //if(p.first != lastP.first && p.second != lastP.second){
  79.             //listX.push_back(lastP);
  80.             //lastP = p;
  81.             //loop++;
  82.             //if (loop == B)
  83.             //{
  84.                 //break;
  85.             //}
  86.         //}
  87.     //}
  88.    
  89.     for (int i = 0; i < B; i++)
  90.     {
  91.         listX.push_back(listV[i]);
  92.         listX.push_back(listV[n-i-1]);
  93.     }
  94.     sort(listV.begin(), listV.end(), comp);
  95.    
  96.     //loop = 0;
  97.     //lastP = listV[0];
  98.     //for (int i = 1; i < n; i++)
  99.     //{
  100.         //pair<int, int> p = listV[i];
  101.         //if(p.first != lastP.first && p.second != lastP.second){
  102.             //listY.push_back(lastP);
  103.             //lastP = p;
  104.             //loop++;
  105.             //if (loop == B)
  106.             //{
  107.                 //break;
  108.             //}
  109.         //}
  110.     //}
  111.     //loop = 0;
  112.     //lastP = listV[n-1];
  113.     //for (int i = 1; i < n; i++)
  114.     //{
  115.         //pair<int, int> p = listV[n-1-i];
  116.         //if(p.first != lastP.first && p.second != lastP.second){
  117.             //listY.push_back(lastP);
  118.             //lastP = p;
  119.             //loop++;
  120.             //if (loop == B)
  121.             //{
  122.                 //break;
  123.             //}
  124.         //}
  125.     //}
  126.      
  127.     for (int i = 0; i < B; i++)
  128.     {
  129.         listY.push_back(listV[i]);
  130.         listY.push_back(listV[n-i-1]);
  131.     }
  132.    
  133.     sort(listX.begin(), listX.end());  
  134.     sort(listY.begin(), listY.end(), comp);
  135.     if (isDiag)
  136.     {
  137.         for (int i = 0; i < listX.size(); i++)
  138.         {
  139.             cout << "x: " << listX[i].first << ", y: " << listX[i].second << endl;
  140.         }
  141.         for (int i = 0; i < listY.size(); i++)
  142.         {
  143.             cout << "y: " << listY[i].second << ", x: " << listY[i].first << endl;
  144.         }
  145.        
  146.     }
  147.    
  148.     int ans = INT_MAX;
  149.     int area = 0;
  150.     int xn, xx, yn, yx;
  151.     int loop = 0;
  152.     for (int i = 0; i < B; i++)
  153.     for (int j = 0; j < B; j++)
  154.     for (int k = 0; k < B; k++)
  155.     for (int l = 0; l < B; l++)
  156.     {
  157.         loop++;
  158.         pair<int, int> b = listX[i];
  159.         pair<int, int> c = listX[listX.size() - 1 - j];
  160.         pair<int, int> d = listY[k];
  161.         pair<int, int> e = listY[listY.size() - 1 - l];
  162.        
  163.         //if (same(b, c) || same(b, d) || same(b, e)
  164.         //|| same(c, d) || same(c, e)
  165.         //|| same(d, e))
  166.         //{
  167.             //continue;
  168.         //}
  169.         //xn = b.first;
  170.         //xx = c.first;
  171.         //yn = d.second;
  172.         //yx = e.second;
  173.        
  174.         xn = min(min(min(b.first, c.first), d.first), e.first);
  175.         xx = max(max(max(c.first, b.first), d.first), e.first);
  176.         yn =  min(min(min(d.second, b.second), c.second), e.second);
  177.         yx = max(max(max(e.second, b.second), c.second), d.second);
  178.        
  179.         if (isDiag) cout << "loop: " << loop<< ", xn: " << xn << ", xx: " << xx << ", yn: " << yn << ", yx: " << yx  ;
  180.         if(isDiag && xn == 0) cout << " >>> b: " << b.first << ", " << b.second << ", c: " << c.first << ", " << c.second << ", d: " << d.first  << ", " << d.second <<", e: " << e.first << ", " << e.second ;
  181.  
  182.  
  183.         int cnt = 0;
  184.         for (int i = 0; i < n; i++)
  185.         {
  186.             pair<int, int> pv = listV[i];
  187.             if ( xn <=  pv.first  && pv.first <= xx
  188.                 && yn <= pv.second && pv.second <= yx)
  189.             {
  190.                 // within border
  191.             }else if (samePoint( pv, b, c, d, e))
  192.             {
  193.                 // same
  194.             }
  195.             else
  196.             {
  197.                 cnt++;
  198.             }
  199.         }
  200.         if(isDiag) cout << ", cnt: "<< cnt ;
  201.         if (cnt <= 3)
  202.         {
  203.             // valid
  204.             area = (xx - xn) * (yx - yn);
  205.             ans = min(ans, area);
  206.             if(isDiag) cout <<", area: " << area << ", ans: " << ans;
  207.         }
  208.        
  209.         if (isDiag) cout << endl;
  210.     }
  211.    
  212.  
  213.      
  214.        
  215.     if (!isDiag) freopen("reduce.out", "w", stdout);
  216.     cout << ans << endl;
  217.    
  218. }
  219.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement