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 ...
随机推荐
- 问题005:如何配置JDK,Java运行环境?
方法一:我的电脑右击-->属性-->高级-->环境变量-->Path 方法二:set path是查询环境变灵, set path=路径
- 第十四篇、OC_新闻查看器
PageTitleView: #import <UIKit/UIKit.h> @class GFBPageTitleView; @protocol GFBPageTitleViewDele ...
- 转载:java分布式服务框架Dubbo的介绍与使用
1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需 ...
- MySQL - FULL JOIN
SQL FULL JOIN 关键字 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行. FULL JOIN 关键字语法 SELECT column_name(s) FROM table_n ...
- docker时区正常,但java获得的时间早了8小时解决方法
我解决容器时区的方法是挂载宿主机的/etc/localtime 到容器的/etc/localtime,这时输入date命令容器时区显示正常,但是跑在容器中的java项目取到的时间却早了8小时. 查阅相 ...
- 基于Ajax提交formdata数据、错误信息展示和局部钩子、全局钩子的校验。
formdata重点: 实例化FormData这个类 循环serializeArray可以节省代码量 图片要用$('#id')[0].files[0]来获得 加上contentType:false和p ...
- hihocoder1015 kmp算法
#1015 : KMP算法 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在 ...
- poj-3253 fence repair(贪心题)
题目描述: Farmer John wants to repair a small length of the fence around the pasture. He measures the fe ...
- 内容提供器(Content Provider)
一个跟数据库很相似的用于与其他程序传递信息的组件,用的也是数据库的CRUD操作 相关权限 注册内容提供者以及权限 <provider android:name=".ContentRes ...
- windows server 2008解决无法PING通问题
今天安装服务器(server 2008),配置完IP地址后,发现局域网其它电脑无法PING通服务器,测线仪测试链路都正常,网线接别的电脑也正常,以为是网卡问题,于是ping了自己的IP,发现能PING ...