CF #330 D2 E
相当于给你一些点,要你最多删除不超过k,使得能使用一个边长为整数的长方形,与XY轴平行,使长方形的面积最小。
上课时拿笔来画画,然后忽然思路就开了,要是比赛也这样就好了~~先按X,Y分别排序,由于K较小,而且,删除的时候肯定会删除最外围的点,所以,可以上下左右枚举删了哪些点,排序后的数组来模拟这个过程,最多4^K个选择,可以过。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #define LL long long using 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); ptx[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; } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步