Rectangular Covering
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2776   Accepted: 790

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个顶点,现在需要用几个长方形取覆盖这些顶点,并且这些长方形中每一个都至少要覆盖住两个顶点。要用总面积尽量小的长方形覆盖住所有的顶点,至少要多少面积的长方形。
思路:先把所有可能的长方形都找出来,并记录每个长方形可以覆盖那几个顶点。设dp[S]:顶点的覆盖情况为状态S时需要的最少的长方形面积。则转移方程为:dp[S]=min(dp[S],dp[k]+j_area);(S=k|points),其中points为某一个长方形j所能覆盖的顶点集,即状态S可以由状态k通过加上长方形j所能覆盖的顶点集转移而来,j_area为长方形j的面积。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define N_MAX 16
#define MOD 100000000
#define INF 0x3f3f3f3f
typedef long long ll;
struct point {
int x, y;
point(int x=,int y=):x(x),y(y) {}
}p[N_MAX];
struct Rec {
int area,points;//points代表当前的rectangle包含的顶点
Rec(int area=,int points=):area(area),points(points) {}
};
int calc_area(const point& a,const point& b) {//计算矩形面积
int s = max(abs(a.x - b.x),)*max(abs(a.y-b.y),);
return s;
}
bool is_inarea(const point &a,const point& b,const point& c) {//点c是否在a,b构成的矩形内
return ((c.x - a.x)*(c.x - b.x) <= && (c.y - a.y)*(c.y - b.y) <= ); }
int n;
int dp[ << N_MAX];//状态i下的最小面积
vector<Rec> rec;
int main() {
while (scanf("%d",&n)&&n) {
rec.clear();
for (int i = ; i < n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
for (int i = ; i < n; i++) {
for (int j = i + ; j < n;j++) {//寻找所有的长方形,并且记录这些长方形包含了哪些顶点
Rec r=Rec(calc_area(p[i], p[j]), ( << i) | ( << j));
for (int k = ; k < n;k++) {
if (k == i || k == j)continue;
if (is_inarea(p[i], p[j], p[k]))
r.points |= << k;
}
rec.push_back(r);
}
}
memset(dp, INF, sizeof(dp));
int allstates = << n;
dp[] = ;
for (int i = ; i < rec.size();i++) {//每加入一个长方形
for (int j = ; j < allstates;j++) {
int newstate = j | rec[i].points;
if (dp[j] != INF&&newstate != j) {
dp[newstate] = min(dp[newstate], dp[j] + rec[i].area);
}
}
}
printf("%d\n",dp[allstates-]);//全部顶点都加入的情况下最小面积
}
return ;
}

最新文章

  1. [MongoDB]入门操作
  2. SDWebImage ReadMe.md文档简单说明
  3. uC/OS-II源码分析
  4. C++数组(指针)作为函数参数
  5. WebService的简单运用添加删除
  6. python 函数运算先于单目运算
  7. DataReport使用手记
  8. php cookie的问题
  9. kernel: INFO: task sadc:14833 blocked for more than 120 seconds.
  10. 【逆向工具】IDA使用5-( string、图形化与视图的切换、图形化显示反汇编地址、自动注释、标签使用)
  11. SSL/TLS中间人攻击
  12. BBR,附CentOS 6/7配置过程
  13. 8 个基于 Lucene 的开源搜索引擎推荐
  14. 1347: Last Digit (周期函数)
  15. 中文乱码—Servlet—SpringMVC
  16. python 去除不可见的控制字符
  17. iOS&#39;s GCD Note
  18. php 导出csv表格文件
  19. 第二章 shell的语法
  20. Java编程介绍

热门文章

  1. Ubuntu 14.04 LTS 触摸板无法使用
  2. 手写promise
  3. k8s的pv和pvc简述
  4. 精通SpringBoot--整合druid监控SQL执行
  5. Python基础函数必学
  6. Python中的dict
  7. 设计模式之第18章-观察者模式(Java实现)
  8. phpmyadmin4.8.1后台getshell
  9. 从shell(终端)中退出python
  10. 为什么对多线程编程这么怕?pthread,sem,mutex,process