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 ...
随机推荐
- React Native 初探
推荐文章 React Native 简介:用 JavaScript 搭建 iOS 应用 (1) React Native 简介:用 JavaScript 搭建 iOS 应用 (2) React Nat ...
- 2.3.3 zerosum 和为零
#include<bits/stdc++.h> using namespace std; ],a; ]={' ','+','-'}; void out() { ;i<a;i++) c ...
- pytthon + Selenium+chrome linux 部署
1,centos7 安装 google-chrome (1) 添加chrome的repo源 vi /etc/yum.repos.d/google.repo [google] name=Google-x ...
- vue-cli的build的文件夹下没有dev-server.js文件,怎么配置mock数据
因为最新版本的vue-cli已经放弃dev-server.js,只需在webpack.dev.conf.js配置就行 新版webpack.dev.conf.js配置如下: 在const portfin ...
- linux正则表达式基础部分
1.什么是正则表达式? 简单的说,正则表达式就是为处理大量的字符串而定义的一套规则和方法, 例如:假设“@”代表boy,“!”代表girl.echo“@!” === “boygirl” 通过定义的这些 ...
- DevOps - 版本控制 - Gogs
Gogs Gogs官网:https://gogs.io Gogs文档:https://gogs.io/docs Gogs配置文件手册:https://gogs.io/docs/advanced/con ...
- 使用VUE开发
<一>VUE的开发分两种,一种是直接在HTML文件中使用,一种是VUE文件的形式开发 1,首先我们先让 HTML 文件支持 VUE 的语法指令提示 2,File -> Setting ...
- 科学计算库Numpy——数值计算
矩阵 求和 乘积 最大值和最小值 最大值和最小值的位置 平均数 标准差 方差 限制 四舍五入
- #3 working with data stored in files && securing your application (PART II)
Security problems is more and more important on the internet today. You can see the problems . This ...
- MySQL之架构与历史(一)
MySQL架构与历史 和其他数据库系统相比,MySQL有点与众不同,它的架构可以在多种不同的场景中应用并发挥好的作用,但同时也会带来一点选择上的困难.MySQL并不完美,却足够灵活,它的灵活性体现在很 ...