The equivalent to give you some points, for you to delete up to no more than K, so that you can use a rectangular edge length as an integer, parallel to the XY axis, so that the area of the rectangle is the smallest.
Class with a pen to draw, and then suddenly thinking on the open, if the game is also good ~ ~ first by x, y respectively, because K is small, and, when deleted is sure to delete the outermost point, so, can be left and right to enumerate what points, sorted array to simulate this process, up to 4^k a choice, can be too.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Vector> #define LL Long longusing namespace Std;///vector<int>f;const int max=100050;struct point{double x, y; int index;} Ptx[max],pty[max];bool cmpx (Point A,point B) {if (a.x<b.x) return True;return false;} BOOL Cmpy (point A,point B) {if (A.Y<B.Y) return True;return false;} BOOL Vis[max];int n,k; LL ans;void dfs (int wl,int wr,int hl,int hr,int counts) {if (!counts) {while (Vis[ptx[wl+1].index]) wl++;while (vis[ptx[ Wr-1].index]) Wr--;while (Vis[pty[hl+1].index]) hl++;while (Vis[pty[hr-1].index]) hr--; ll x= (ptx[wr-1].x-ptx[wl+1].x==0) 1: (ll) (ptx[wr-1].x-ptx[wl+1].x+0.5); ll y= (pty[hr-1].y-pty[hl+1].y==0) 1: (ll) (pty[hr-1].y-pty[hl+1].y+0.5); Ans=min (ans,x*y); return;} for (int i=wl+1;; i++) {if (Vis[ptx[i].index]) Continue;vis[ptx[i].index]=true;dfs (i,wr,hl,hr,counts-1); vis[ptx[i].index]=false; break;} for (int i=wr-1;; i--) {if (Vis[ptx[i].index]) Continue;vis[ptx[i].index]=true;dfs (wl,i,hl,hR,COUNTS-1); vis[ptx[i].index]=false;break;} for (int i=hl+1;; i++) {if (Vis[pty[i].index]) Continue;vis[pty[i].index]=true;dfs (wl,wr,i,hr,counts-1); vis[pty[i].index]=false; break;} for (int i=hr-1;; i--) {if (Vis[pty[i].index]) Continue;vis[pty[i].index]=true;dfs (wl,wr,hl,i,counts-1); vis[pty[i].index]=false; Break;}} int main () {while (scanf ("%d%d", &n,&k)!=eof) {double x1,y1,x2,y2;for (int i=0;i<n;i++) {scanf ("%lf%lf%lf%lf ", &x1,&y1,&x2,&y2);p tx[i].x= (x1+x2)/2;ptx[i].y= (y1+y2)/2;ptx[i].index=i;pty[i]=ptx[i];vis[i]= false;} Sort (ptx,ptx+n,cmpx); sort (pty,pty+n,cmpy); ans= (1ll<<62); if (k==n-1) {cout<<1<<endl;continue;} DFS ( -1,n,-1,n,k); Cout<<ans<<endl;}}
CF #330 D2 E