Rectangular Covering
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2727   Accepted: 769

Description

n points are given on the Cartesian plane. Now you have to use some rectangles whose sides are parallel to the axes to cover them. Every point must be covered. And a point can be covered by several rectangles. Each rectangle should cover at least two points including those that fall on its border. Rectangles should have integral dimensions. Degenerate cases (rectangles with zero area) are not allowed. How will you choose the rectangles so as to minimize the total area of them?

Input

The input consists of several test cases. Each test cases begins with a line containing a single integer n (2 ≤ n ≤ 15). Each of the next n lines contains two integers xy (−1,000 ≤ xy ≤ 1,000) giving the coordinates of a point. It is assumed that no two points are the same as each other. A single zero follows the last test case.

Output

Output the minimum total area of rectangles on a separate line for each test case.

Sample Input

2
0 1
1 0
0

Sample Output

1

Hint

The total area is calculated by adding up the areas of rectangles used.

Source

题意:坐标平面上有n各点,用任意大小(非零)的矩形覆盖它们,每个矩形至少覆盖亮点,求最省的矩形的总面积。

解析:先预处理,将n个点两个两个组合构成多个矩形,然后将在矩形内部的点更新进矩形中。

然后就是dp的过程了:dp[0] = 0,初始时集合无点,面积为0,dp[nowS] = min ( dp[nowS], dp[s] + area),当前的点集的矩阵取,还是不取。

代码:

 //#include "bits/stdc++.h"
#include "cstdio"
#include "map"
#include "set"
#include "cmath"
#include "queue"
#include "vector"
#include "string"
#include "cstring"
#include "time.h"
#include "iostream"
#include "stdlib.h"
#include "algorithm"
#define db double
#define ll long long
//#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define inf 0x3f3f3f3f
#define rep(i, x, y) for(int i=x;i<=y;i++)
const int N = 1e5 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0); using namespace std;
int n;
int x[],y[];
struct rec
{
int are,cov;
rec(){};
rec(int _are,int _cov) {are=_are,cov=_cov;}
void addP(int x) {cov|=(<<x);}//加点
};
int area(int i,int j)
{
return max(abs(x[i]-x[j]),)*max(abs(y[i]-y[j]),);
}
bool cal(int i,int j,int k){//判断第三点是否在前两点确定的矩形上
return (x[i]-x[k])*(x[j]-x[k])<=&&(y[i]-y[k])*(y[j]-y[k])<=;
}
vector<rec> e;
int f[N];
int main()
{
while(scanf("%d",&n)==&&n!=)
{
e.clear();
for(int i=;i<n;i++) ci(x[i]),ci(y[i]);
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
rec tmp(area(i,j),(<<i)|(<<j));
for(int k=;k<n;k++) if(cal(i,j,k)) tmp.addP(k);//合并点集
e.push_back(tmp);
}
}
memset(f,inf, sizeof(f));
f[]=;
for(int i=;i<e.size();i++){
for(int j=;j<(<<n);j++){//从0开始更新,每次加入点集
int S=j|e[i].cov;
if(f[j]!=inf) f[S]=min(f[S],f[j]+e[i].are);
}
}
pi(f[(<<n)-]);
}
return ;
}

最新文章

  1. SQL/T-SQL实例参考
  2. flash中网页跳转总结
  3. 项目管理、测试管理、代码bug 管理
  4. LeetCode(84) Largest Rectangle in Histogram
  5. MyEclipse下如何安装和使用ibatis插件(网上的资料对于myeclipse8.5根本就是没有用的,所以我还是自己选择了装了一个eclipse,然后将插件装在了eclipse中)
  6. malloc与kmalloc
  7. Android(java)学习笔记109:通过反射获取成员变量和成员方法并且使用
  8. sql null值
  9. jQuery Ajax 实例 具体介绍$.ajax、$.post、$.get的使用
  10. UML中九种图的理解
  11. AngularJs打造一个简易权限系统
  12. java 线程之executors线程池
  13. iOS开发证书都显示“此证书的签发者无效”,更新WWDR Certificate证书后还是显示无效
  14. DevExpress ASP.NET Core Controls 2019发展蓝图(No.1)
  15. Spring 中的类加载机制 - ClassLoader
  16. MyBatis分步查询的延迟加载
  17. Twitter雪花算法 SnowFlake算法 的java实现
  18. Spring事务异常回滚,捕获异常不抛出就不会回滚
  19. 关于Suppressing notification from package com.xxx.xxx by user request.的异常
  20. CentOS7.5搭建Solr7.4.0集群服务

热门文章

  1. JavaScript精简代码 非一般的写法(转载)
  2. 转:清除arcsde空间垃圾数据以及解决sde图层名称被占用的问题
  3. VMware下,windows7无法自动更新,故障80072EE2
  4. 初学React:组件的样式
  5. ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id
  6. 【CCPC-Wannafly Winter Camp Day4 (Div1) J】跑跑跑路(爬山)
  7. Uva 11235 RMQ问题
  8. 2017.11.14 C语言---指针的学习
  9. 预处理-04-#if defined和#if !defined
  10. django中间件及中间件实现的登录验证