Description

  Your boss once had got many copies of a treasure map. Unfortunately, all the copies are now broken to many rectangular pieces, and what make it worse, he has lost some of the pieces. Luckily, it is possible to figure out the position of each piece in the original map. Now the boss asks you, the talent programmer, to make a complete treasure map with these pieces. You need to make only one complete map and it is not necessary to use all the pieces. But remember, pieces are not allowed to overlap with each other (See sample 2).

  题目就是找到几个矩形来覆盖一个大的矩形,而且要求不能重叠。

  构造01矩阵的话就是把n*m这个大矩形的每一个点都作为一列(也就是有n*m列),然后把每一个可选择矩形都当做一行。。。

代码如下:

#include<iostream>
#include<cstring> using namespace std; const int INF=10e8;
const int MaxN=;
const int MaxM=*;
const int MaxNode=*+; struct DLX
{
int n,m,size;
int U[MaxNode],D[MaxNode],L[MaxNode],R[MaxNode],col[MaxNode];
int S[MaxM],H[MaxN];
int ans; void init(int _n,int _m)
{
n=_n;
m=_m; ans=INF; for(int i=;i<=m;++i)
{
S[i]=;
U[i]=D[i]=i;
L[i]=i-;
R[i]=i+;
}
L[]=m;
R[m]=; size=m; for(int i=;i<=n;++i)
H[i]=-;
} void Link(int r,int c) //r is row , c is col.
{
col[++size]=c;
++S[c]; U[size]=U[c];
D[U[c]]=size;
D[size]=c;
U[c]=size; if(H[r]<)
H[r]=L[size]=R[size]=size;
else
{
R[size]=H[r];
L[size]=L[H[r]];
R[L[H[r]]]=size;
L[H[r]]=size;
}
} void remove(int c)
{
R[L[c]]=R[c];
L[R[c]]=L[c]; for(int i=D[c];i!=c;i=D[i])
for(int j=R[i];j!=i;j=R[j])
{
D[U[j]]=D[j];
U[D[j]]=U[j];
--S[col[j]];
}
} void resume(int c)
{
for(int i=U[c];i!=c;i=U[i])
for(int j=L[i];j!=i;j=L[j])
{
++S[col[j]];
D[U[j]]=U[D[j]]=j;
} R[L[c]]=L[R[c]]=c;
} void Dance(int d)
{
if(R[]==)
{
if(d<ans)
ans=d; return;
} if(d>ans)
return; int c=R[]; for(int i=R[];i!=;i=R[i])
if(S[i]<S[c])
c=i; remove(c); for(int i=D[c];i!=c;i=D[i])
{
for(int j=R[i];j!=i;j=R[j])
remove(col[j]); Dance(d+); for(int j=L[i];j!=i;j=L[j])
resume(col[j]);
} resume(c);
}
}; DLX dlx; int main()
{
ios::sync_with_stdio(false); int T;
int n,m,p;
int x1,x2,y1,y2;
cin>>T; while(T--)
{
cin>>n>>m>>p; dlx.init(p,(n)*(m)); for(int i=;i<=p;++i)
{
cin>>x1>>y1>>x2>>y2; for(int x=x1;x<x2;++x)
for(int y=y1;y<y2;++y)
dlx.Link(i,y*(n)+x+);
} dlx.Dance(); if(dlx.ans==INF)
cout<<-<<endl;
else
cout<<dlx.ans<<endl;
} return ;
}

(简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。的更多相关文章

  1. zoj - 3209 - Treasure Map(精确覆盖DLX)

    题意:一个 n x m 的矩形(1 <= n, m <= 30),现给出这个矩形中 p 个(1 <= p <= 500)子矩形的左下角与右下角坐标,问最少用多少个子矩形能够恰好 ...

  2. ZOJ 3209 Treasure Map(精确覆盖)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  3. ZOJ 3209 Treasure Map DLX

    用最少的矩阵覆盖n*m的地图.注意矩阵不能互相覆盖. 这里显然是一个精确覆盖,但因为矩阵拼接过程中,有公共的边,这里须要的技巧就是把矩阵的左边和以下截去一个单位. #include <stdio ...

  4. (简单) HUST 1017 Exact cover , DLX+精确覆盖。

    Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is ...

  5. zoj 3209.Treasure Map(DLX精确覆盖)

    直接精确覆盖 开始逐行添加超时了,换成了单点添加 #include <iostream> #include <cstring> #include <cstdio> ...

  6. ZOJ 3209 Treasure Map 精确覆盖

    题目链接 精确覆盖的模板题, 把每一个格子当成一列就可以. S忘记初始化TLE N次, 哭晕在厕所...... #include<bits/stdc++.h> using namespac ...

  7. ZOJ 3209 Treasure Map (Dancing Links 精确覆盖 )

    题意 :  给你一个大小为 n * m 的矩形 , 坐标是( 0 , 0 ) ~ ( n , m )  .然后给你 p 个小矩形 . 坐标是( x1 , y1 ) ~ ( x2 , y2 ) , 你选 ...

  8. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  9. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

随机推荐

  1. ListBox之类控件的Item项显示对象的两个属性

    wpf项目中,ListBox绑定对象集合,ListBoxItem要显示对象的两个属性,例如:显示员工的工号和姓名. 之前我的做法是在Employee员工类中添加一个"NumAndName&q ...

  2. First()、FirstOrDefault()、Single() 和 SingleOrDefault()的区别

    Enumerable.First() 方法:返回序列中的第一个元素,如果源序列为空,则抛异常. Enumerable.FirstOrDefault ()方法返回序列中的第一个元素:如果序列中不包含任何 ...

  3. 转 : 如何用sys as sysdba权限连接数据库进行EXP/IMP

    使用sys as sysdba权限进行EXP/IMP与其它用户稍有不同,详细内容如下(摘自metalink) Applies to: Oracle Server - Enterprise Editio ...

  4. 内存管理 & 内存优化技巧 浅析

    内存管理 浅析 下列行为都会增加一个app的内存占用: 1.创建一个OC对象: 2.定义一个变量: 3.调用一个函数或者方法. 如果app占用内存过大,系统可能会强制关闭app,造成闪退现象,影响用户 ...

  5. shell写多行到文件中

    用cat或者echo命令输入多行数据到指定文本 #!/bin/sh ( cat <<EOF start() { echo "start" } EOF ) > Ma ...

  6. android代码实现免提功能

    初始化AudioManager: private static AudioManager audioManager; 实现免提功能方法 protected void setSpeekModle() { ...

  7. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. Windows API 之 CreateFile、CreateFileMapping 、MapViewOfFile

    CreateFile Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: ...

  9. Eclipse中Ctrl+Alt+Down和Ctrl+Alt+Up不起作用

    不起作用是因为跟因特尔的快捷键冲突. 1.在桌面上右键,选择“图形属性......” 2.选择“选项和支持” 3.更改快捷键. 注意:单纯禁用英特尔的快捷键可能不起作用.

  10. 剑指offer替换空格

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...