poj 2836 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 x, y (−1,000 ≤ x, y ≤ 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
#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 ;
}
poj 2836 Rectangular Covering的更多相关文章
- POJ 2836 Rectangular Covering(状压DP)
[题目链接] http://poj.org/problem?id=2836 [题目大意] 给出二维平面的一些点,现在用一些非零矩阵把它们都包起来, 要求这些矩阵的面积和最小,求这个面积和 [题解] 我 ...
- poj 2836 Rectangular Covering(状态压缩dp)
Description n points are given on the Cartesian plane. Now you have to use some rectangles whose sid ...
- POJ 2836 Rectangular Covering (状压DP)
题意:平面上有 n (2 ≤ n ≤ 15) 个点,现用平行于坐标轴的矩形去覆盖所有点,每个矩形至少盖两个点,矩形面积不可为0,求这些矩形的最小面积. 析:先预处理所有的矩形,然后dp[s] 表示 状 ...
- POJ 2836 状压DP
Rectangular Covering Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2727 Accepted: 7 ...
- POJ 2836:Rectangular Covering(状态压缩DP)
题目大意:在一个平面内有若干个点,要求用一些矩形覆盖它们,一个矩形至少覆盖两个点,可以相互重叠,求矩形最小总面积. 分析: 数据很小,很容易想到状压DP,我们把点是否被覆盖用0,1表示然后放在一起得到 ...
- POJ2836 Rectangular Covering(状压DP)
题目是平面上n个点,要用若干个矩形盖住它们,每个矩形上至少要包含2个点,问要用的矩形的面积和最少是多少. 容易反证得出每个矩形上四个角必定至少覆盖了两个点.然后就状压DP: dp[S]表示覆盖的点集为 ...
- Rectangular Covering [POJ2836] [状压DP]
题意 平面上有 n (2 ≤ n ≤ 15) 个点,现用平行于坐标轴的矩形去覆盖所有点,每个矩形至少盖两个点,矩形面积不可为0,求这些矩形的最小面积. Input The input consists ...
- 我的刷题单(8/37)(dalao珂来享受切题的快感
P2324 [SCOI2005]骑士精神 CF724B Batch Sort CF460C Present CF482A Diverse Permutation CF425A Sereja and S ...
- poj 1266 Cover an Arc.
http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
随机推荐
- 问题003:JDK文件夹下的bin有什么作用?javac.exe和java.exe双击后为什么一闪而过,没了?
bin (binary)二进制 ,JDK当中所有的可以执行的二进制应用程序都放在其中.其中都是*.exe文件,表示可以直接执行程序. javac.exe和java.exe双击后为什么一闪而过,没了?因 ...
- Hotkeys.js 2.0.2 发布,JS 网页快捷键设置,捕获键盘输入和输入的组合键快捷键,它没有依赖
这是一个强健的 Javascript 库用于捕获键盘输入和输入的组合键,它没有依赖,压缩只有只有(~3kb),gzip:1.9k. 更新内容: 添加测试用例: 添加更多特殊键支持: 修复bug. __ ...
- v4l2解析
v4l2的学习建议和流程解析: http://www.cnblogs.com/silence-hust/p/4464291.html 补充: 枚举设备所支持的image format: VIDIOC_ ...
- nginx限制ip访问某些特定url
这两天百度云给我发了一些安全报警邮件,其中一条是有些陌生ip频繁尝试登录我的后台账户,也就是www.runstone.top/admin.给出的建议是限制这些ip访问/admin/这个url,于是经过 ...
- Python基础-Python注释
一.什么是注释.特性 1.一段文字性的描述,通过注释,可以解释和明确Python代码的功能,并记录将来要修改的地方. 2.当程序处理时,Python解释器会自动忽略,不会被当做代码进行处理 二.注释的 ...
- Iframe父子间元素操作
1.在父页面 获取iframe子页面的元素 (在同域的情况下 且在http://下测试,且最好在iframe onload加载完毕后 dosomething...) js写法 a.通过contentW ...
- PKI
公钥基础设施(Public Key Infrastructure,简称PKI)是眼下网络安全建设的基础与核心,是电子商务安全实施的基本保障,因此,对PKI技术的研究和开发成为眼下信息安全领域的热点.本 ...
- 大道至简读后感——JAVA伪代码
import.java.Dadaozhijain public class YuGongYiShan { //愚公移山 愚公={项目管理人员}: 原始需求={惩山北之塞,出入之迂也}: 沟通方式={聚 ...
- Admin站点
使用admin站点 a.在settings.py中设置语言和时区 LANGUAGE_CODE = 'zh-hans' # 使用中国语言 TIME_ZONE = 'Asia/Shanghai' # 使用 ...
- 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数
题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...