题面链接
https://www.acwing.com/problem/content/description/1828/
思路
因为只用去处一只奶牛,所以这只奶牛肯定尽可能远离大部分牛群,所以我们很容易想到去除四个角然后计算剩下的牛群能围成的面积是多少就好了,所以我们定义四个数组,然后不同的方式排序就好了
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define BPII pair<int,int>
#define INF 0x3f3f3f3f3f3f3f3f
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){return -x & x;}
const int N = 2e6+10;
int n,m,q;
int x,y;
vector<PII> a,b,c,d;
bool cmp1(PII a,PII b){
return a.second < b.second;
}
bool cmp2(PII a,PII b){
return a.second < b.second;
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
cin>>n;
for(int i = 0;i < n; ++i) {
cin>>x>>y;
a.push_back({x,y});
b.push_back({x,y});
c.push_back({y,x});
d.push_back({y,x});
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(c.begin(),c.end());
sort(d.begin(),d.end());
int ans = INF;
int x1 = a[n-2].first - a[0].first;
sort(a.begin(),a.begin()+a.size()-1,cmp1);
int y1 = a[n-2].second - a[0].second;
ans = min(ans,x1*y1);
int x2 = b[n-1].first - b[1].first;
sort(b.begin()+1,b.end(),cmp1);
int y2 = b[n-1].second - b[1].second;
ans = min(ans,x2*y2);
y1 = c[n-2].first - c[0].first;
sort(c.begin(),c.begin()+c.size()-1,cmp1);
x1 = c[n-2].second - c[0].second;
ans = min(ans,x1*y1);
y2 = d[n-1].first - d[1].first;
sort(d.begin()+1,d.end(),cmp1);
x2 = d[n-1].second - d[1].second;
ans = min(ans,x2*y2);
ans = max(0LL,ans);
cout<<ans<<endl;
return 0;
}
|