ZOJ 3209 Treasure Map 精确覆盖
精确覆盖的模板题, 把每一个格子当成一列就可以。
S忘记初始化TLE N次, 哭晕在厕所......
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = ;
const int maxNode = ;
struct DLX {
int L[maxNode], R[maxNode], U[maxNode], D[maxNode], row[maxNode], col[maxNode];
int S[maxn], H[maxn], deep, sz, n, m, num;
void remove(int c) {
L[R[c]] = L[c];
R[L[c]] = R[c];
for(int i = D[c]; i!=c; i = D[i])
for(int j = R[i]; j!=i; j = R[j]) {
U[D[j]] = U[j];
D[U[j]] = D[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]] = j;
U[D[j]] = j;
}
R[L[c]] = c;
L[R[c]] = c;
}
void dfs(int d) {
if(d>=deep)
return ;
if(R[] == ) {
deep = min(d, deep);
return ;
}
int c = R[];
for(int i = R[]; i!=; i = R[i])
if(S[c]>S[i])
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]);
dfs(d+);
for(int j = L[i]; j!=i; j = L[j])
resume(col[j]);
}
resume(c);
return ;
}
void add(int r, int c) {
sz++;
col[sz] = c;
S[c]++;
U[sz] = U[c];
D[sz] = c;
D[U[c]] = sz;
U[c] = sz;
if(~H[r]) {
R[sz] = H[r];
L[sz] = L[H[r]];
L[R[sz]] = sz;
R[L[sz]] = sz;
} else {
H[r] = L[sz] = R[sz] = sz;
}
}
void init(){
mem1(H);
for(int i = ; i<=n; i++) {
R[i] = i+;
L[i] = i-;
D[i] = U[i] = i;
}
R[n] = ;
L[] = n;
mem(S);
sz = n;
deep = inf;
}
void solve() {
scanf("%d%d%d", &n, &m, &num);
n *= m;
init();
int x1, y1, x2, y2;
int cnt = ;
while(num--) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
for(int i = x1+; i<=x2; i++) {
for(int j = y1+; j<=y2; j++) {
add(cnt, (i-)*m+j);
}
}
cnt++;
}
dfs();
if(deep == inf) {
puts("-1");
} else {
printf("%d\n", deep);
}
}
}dlx;
int main()
{
int t;
cin>>t;
while(t--) {
dlx.solve();
}
}
ZOJ 3209 Treasure Map 精确覆盖的更多相关文章
- ZOJ 3209 Treasure Map(精确覆盖)
Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 KB Your boss once had got many copies of ...
- (简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。
Description Your boss once had got many copies of a treasure map. Unfortunately, all the copies are ...
- zoj 3209.Treasure Map(DLX精确覆盖)
直接精确覆盖 开始逐行添加超时了,换成了单点添加 #include <iostream> #include <cstring> #include <cstdio> ...
- zoj - 3209 - Treasure Map(精确覆盖DLX)
题意:一个 n x m 的矩形(1 <= n, m <= 30),现给出这个矩形中 p 个(1 <= p <= 500)子矩形的左下角与右下角坐标,问最少用多少个子矩形能够恰好 ...
- ZOJ 3209 Treasure Map (Dancing Links 精确覆盖 )
题意 : 给你一个大小为 n * m 的矩形 , 坐标是( 0 , 0 ) ~ ( n , m ) .然后给你 p 个小矩形 . 坐标是( x1 , y1 ) ~ ( x2 , y2 ) , 你选 ...
- ZOJ 3209 Treasure Map (Dancing Links)
Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 KB Your boss once had got many copies of ...
- ZOJ 3209 Treasure Map (Dancing Links)
Treasure Map Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- ZOJ 3209 Treasure Map DLX
用最少的矩阵覆盖n*m的地图.注意矩阵不能互相覆盖. 这里显然是一个精确覆盖,但因为矩阵拼接过程中,有公共的边,这里须要的技巧就是把矩阵的左边和以下截去一个单位. #include <stdio ...
- ZOJ3209 Treasure Map —— Danc Links 精确覆盖
题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 ...
随机推荐
- asp.net RadioButton控件基础
RadioButton按钮呢,必须要设置groupname属性的值才能将多个RadioButton按钮设置为单选按钮,当AutoPostBack="true"的时候,在change ...
- CentOS6.3 下启动Oracle service和listener
一.启动Oracle数据库和监听器 首先切换到Oracle专有用户: [root@NJZYY06 ~]# su - oracle [oracle@NJZYY06 ~]$ 1.启动数据库: [oracl ...
- ORA-01950: 对表空间 'NAMETABLESPACE' 无权限
只要将Role下的Resource权限赋予给当前用户即可解决上述问题.
- iOS-NSAttributedString自定义文字变色
1.使用注意: 1.给UILabel设置attributedText了会导致给UILabel中text,font,textColor,shadowColor,shadowOffset,textAlig ...
- C++引用和函数返回值
这是老师上课讲的内容,现在把它写下来,一方面当做复习,另一方面真的想学点东西.废话不多说,先贴上测试的代码: #include <iostream.h> float temp; float ...
- 随意记的一点 js 笔记
1. 给未经声明的变量赋值在严格模式下会导致抛出 ReferenceError 错误(意思是,所有变量都必须用 var 去定义,不能在函数内部定义全局变量): 2. 在严格模式下,不能定义名为 eva ...
- [原创]obj-c编程17:键值观察(KVO)
原文链接:[原创]obj-c编程17:键值观察(KVO) 系列专栏链接:objective-c 编程系列 说完了前面一篇KVC,不能不说说它的应用KVO(Key-Value Observing)喽.K ...
- Unicode字符列表
注:除非有特别指明,否则以下符号皆属“半角”而非“全角”. 代码 显示 描述 U+0020 空格 U+0021 ! 叹号 U+0022 " 双引号 U+0023 # 井号 U+0024 $ ...
- linux基础--chkconfig 详解
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...
- Oracle中强行断开用户连接的方法
版权声明:本文为博主原创文章,未经博主允许不得转载. 首先查找目标用户的当前进程,注意是serial#而不是serial,网上有的介绍漏掉了#: select sid,serial# from v$s ...