正题
大意
有n块巧克力,一个a*b的网格,如果网格可以完全包括一块巧克力就可以获得这块巧克力,求最多能获得的巧克力数量
解题思路
枚举点(在巧克力上的)和各种情况,然后判断这种情况包括多少个巧克力,然后取最大值。
代码
#include<cstdio>
#include<algorithm>
using namespace std;
int x[101],y[101],n,a,b,x1,y1,x2,y2,lx[51],ry[51],rx[51],ly[51],s,maxs;
int xx,xy,yx,yy;
int answer(int x1,int y1,int x2,int y2)//判断包含多少个巧克力
{int s=0;for (int i=1;i<=n;i++)if (lx[i]>=x1 && ly[i]>=y1 && rx[i]<=x2 && ry[i]<=y2) s++;return s;
}
int main()
{freopen("cho.in","r",stdin);freopen("cho.out","w",stdout);scanf("%d",&n);for (int i=1;i<=n;i++){scanf("%d%d%d%d",&xx,&xy,&yx,&yy);lx[i]=min(xx,yx);ly[i]=min(xy,yy);rx[i]=max(xx,yx);ry[i]=max(xy,yy);x[i*2-1]=xx;y[i*2-1]=xy;x[i*2]=yx;y[i*2]=yy;}scanf("%d%d",&a,&b);for (int i=1;i<=n*2;i++){maxs=max(maxs,answer(x[i],y[i],x[i]+a,y[i]+b));maxs=max(maxs,answer(x[i]-a,y[i],x[i],y[i]+b));maxs=max(maxs,answer(x[i],y[i]-b,x[i]+a,y[i]));maxs=max(maxs,answer(x[i]-a,y[i]-b,x[i],y[i]));maxs=max(maxs,answer(x[i],y[i],x[i]+b,y[i]+a));maxs=max(maxs,answer(x[i]-b,y[i],x[i],y[i]+a));maxs=max(maxs,answer(x[i],y[i]-a,x[i]+b,y[i]));maxs=max(maxs,answer(x[i]-b,y[i]-a,x[i],y[i]));//枚举8种情况}printf("%d",maxs);
}