#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=1e5+10,M=0,Z=1e9+7,ms63=1061109567;
int n,m;
struct A
{
int v;
int p;
bool operator < (const A&b)const
{
if(v!=b.v)return v<b.v;
else return p<b.p;
}
}x[N],y[N];
int e[N];
int main()
{
int x1,y1,x2,y2;
while(~scanf("%d%d",&n,&m))
{
for(int i=1;i<=n;++i)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x[i].v=(x2+x1);x[i].p=i;
y[i].v=(y1+y2);y[i].p=i;
}
sort(x+1,x+n+1);
sort(y+1,y+n+1);
LL ans=4e18;
int num=0;
for(int bot=1;;++bot)
{
for(int top=n;;--top)
{
for(int lft=1;;++lft)
{
for(int rgt=n;;--rgt)
{
LL a=max((y[top].v-y[bot].v),2);if(a&1)++a;
LL b=max((x[rgt].v-x[lft].v),2);if(b&1)++b;
gmin(ans,a*b);
if(++e[x[rgt].p]==1)++num;
if(num>m){while(rgt<=n)if(--e[x[rgt++].p]==0)--num;break;}
}
if(++e[x[lft].p]==1)++num;
if(num>m){while(lft>=1)if(--e[x[lft--].p]==0)--num;break;}
}
if(++e[y[top].p]==1)++num;
if(num>m){while(top<=n)if(--e[y[top++].p]==0)--num;break;}
}
if(++e[y[bot].p]==1)++num;
if(num>m){while(bot>=1)if(--e[y[bot--].p]==0)--num;break;}
}
printf("%lld\n",ans/4);
}
return 0;
}
/*
【trick&&吐槽】
the refrigerator door must be rectangle,
and both the length and the width of the door must be positive integers.
没看题导致wa一发呀>_<,读题读题好重要!
1,用for循环实现类递归的搜索形式的话,还是在当步实现回溯比较方便清晰。
2,哪怕是e[x--]--这样的操作,都是在初始操作完成之后再进行两个--操作的。
【题意】
给你n(1<=n<=1e5)个矩形,以左下角和右上角的形式给出,每个矩形的坐标给在[1,1e9]范围。
我们想要最多去除k个矩形,(0<=k<=min(n-1,10))。
使得我们可以使用一个面积尽可能小的大矩形,包含剩下所有矩形的重心。
让你输出这个大矩形的面积(大矩形的长和宽都必须为正整数)
【类型】
贪心
【分析】
我们发现,很显然,我们有意义的对于矩形的去除,是最上,最下,最左,最右的矩形。
于是我们对所有矩形的重心排序。放到横坐标排一次,再放到纵坐标排一次。
接下来枚举上下左右各去除了多少个矩形,如果满足限制条件,则更新答案。这道题就做完啦!
然而还有一点,就是重心的横纵坐标是可能为.5的,这个会带来精度上的误差和困扰。
为了解决这个问题,我们把重心的坐标扩大2倍。然后再贪。
但是要保证所有数都是偶数,这样才能有实际的长和宽都为整数。
这样这道题就做完啦!
【时间复杂度&&优化】
O(nlogn+k^4)
【数据】
2 0
1 1 2 2
3 3 5 5
重心分别为——
(1.5,1.5)
(4,4)
那么矩形的面积就是3*3=9
然而5*5/4的答案却只有6.
所以可见审题还是非常重要呀!虽然这题不知道怎么这样的错误给放过去了2333
*/
【Codeforces Round 330 (Div 2)E】【贪心 暴力】Edo and Magnets 给定矩形最多去除m个,最小面积矩形使得覆盖所有小矩形重心
最新推荐文章于 2019-11-25 20:30:07 发布