zoukankan      html  css  js  c++  java
  • hihocoder #1442 : Smallest Rectangle

     题意 :

    给N个点,

    从里面随机取四个点,如果能构成矩形,求最小的矩形面积

    题解:

    一旦对角两个点确定 四个点都确定 

    复杂度N方

    #include<bits/stdc++.h>
    #define rep(i,a,n) for(int i=a;i<=n;++i)
    #define per(i,a,n) for(int i=n;i>=a;--i)
    #define pb push_back
    #define fi first
    #define se second
    #define io std::ios::sync_with_stdio(false)
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    const int P = 1e9+7, INF = 0x3f3f3f3f;
    
    ll gcd(ll a,ll b)
    {
        return b?gcd(b,a%b):a;
    }
    ll qpow(ll a,ll n)
    {
        ll r=1%P;
        for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
        return r;
    }
    const int maxn=1e4+10;
    
    int main()
    {
       io;
       int n;
       cin>>n;
       map<pii,int> mp;
       std::vector<pii> v;
       for(int i=1;i<=n;i++)
       {
          pii x;
          cin>>x.fi>>x.se;
          mp[x]++;
          v.push_back(x);
       }
       ll ans=1e18;
       for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
           int x1=v[i].fi,y1=v[i].se;
           int x2=v[j].fi,y2=v[j].se;
           if(x1==x2||y1==y2) continue;
           if(mp[pii(x1,y2)]&&mp[pii(x2,y1)]) ans=min(ans,1ll*abs(x1-x2)*abs(y1-y2));
        }
        if(ans==1e18) return puts("-1"),0;
        cout<<ans<<endl;
    }
  • 相关阅读:
    使用GitHub+hexo搭建个人独立博客
    HDU 3038
    POJ 1417
    HDU 1213
    ZOJ 3781
    ZOJ 3780
    ZOJ 3777
    HDU 3045
    HDU 3480
    POJ 1180
  • 原文地址:https://www.cnblogs.com/acmLLF/p/13496789.html
Copyright © 2011-2022 走看看