poj 3681 Finding the Rectangle 尺取法解最小矩形覆盖问题
来源:互联网 发布:sql创建用户并授权 编辑:程序博客网 时间:2024/06/05 10:44
题意:
平面上有n个点,现在要求一个面积最小的矩形能完全覆盖其中的m个点(边界不算)。
分析:
求满足某个性质的最小区间的问题尺取法比二分还要高效,这题可以在x上暴力枚举,在y上用尺取法(在x,y上都用尺取法是不对的)。
代码:
//poj 3681//sep9#include <iostream>#include <algorithm>using namespace std;int n,m,ans;struct P{int x,y;}pnt1[256],pnt2[256];int cmp1(P a,P b){return a.x<b.x;}int cmp2(P a,P b){return a.y<b.y;}int vis[256];void judge(int lx,int rx){int y[256],u=0,d=0;for(int i=0;i<n;++i)if(pnt2[i].x>=lx&&pnt2[i].x<=rx){y[u++]=pnt2[i].y;if(u-d==m){ans=min(ans,(y[u-1]-y[d]+2)*(rx-lx+2));++d;}}}int main(){int cases;scanf("%d",&cases);while(cases--){scanf("%d%d",&n,&m);for(int i=0;i<n;++i){scanf("%d%d",&pnt1[i].x,&pnt1[i].y);pnt2[i]=pnt1[i];}sort(pnt1,pnt1+n,cmp1);sort(pnt2,pnt2+n,cmp2);ans=INT_MAX;int l,r;for(int i=0;i<n;++i)for(int j=i;j<n;++j)judge(pnt1[i].x,pnt1[j].x);printf("%d\n",ans);}return 0;}
0 0
- poj 3681 Finding the Rectangle 尺取法解最小矩形覆盖问题
- UVA10173Smallest Bounding Rectangle+最小矩形覆盖
- POJ3681-Finding the Rectangle
- 矩形覆盖 rectangle cover
- POJ 2125 --Destroying The Graph【最小割解决 "最小点权覆盖问题" && 输出解(割边集) && 各种不懂】
- hdu5251最小矩形覆盖
- UVa 12307 Smallest Enclosing Rectangle(旋转卡壳+最小覆盖矩形)
- 【最小矩形面积覆盖:凸包+旋转卡壳】UVA 10173Smallest Bounding Rectangle
- [旋转卡壳] BZOJ 1185 [HNOI2007]最小矩形覆盖 && 2218 Uva10173 Smallest Bounding Rectangle
- hdu 1937 Finding Seats 尺取法
- poj 2376 最小区间覆盖问题
- poj 2594(最小路径覆盖问题)
- bzoj1185[HNOI2007]最小矩形覆盖
- bzoj1185【HNOI2007】最小矩形覆盖
- 1185: [HNOI2007]最小矩形覆盖
- 【HNOI2007】bzoj1185 最小矩形覆盖
- POJ 3276 尺取法 反转问题
- POJ-3740-Easy Finding【DLX精确覆盖】
- 【Android单元测试系列】TestCase选择
- cocos2dx 自动添加所有cpp文件到android.mk
- 聊天室 利用多线程
- Unique Paths 算法详解
- php中安全模式safe_mode配置教程
- poj 3681 Finding the Rectangle 尺取法解最小矩形覆盖问题
- 瘦针灸能瘦多少斤Vxin616628874
- unity3d移动平台性能优化专题16:性能优化实战之20个复杂单位战斗
- HttpModule与HttpHandler详解
- 架构师之路(39)---IoC框架
- 读书笔记-于渊(一个操作系统的实现)一
- 求数组中第K大的数
- Agenda: June 24, 2015 2100 UTC
- linux下的c/c++调试器gdb