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 ...
随机推荐
- EXCEL破冰之旅
1 背景 EXCEL用于日常数据分析的工具中,最便利并且最强大的莫属透视表了.因为透视表对原始数据有一定的要求,所以本次的破冰之旅也将把焦点放在如何整理基础数据这个方面. 1.1 初识透视表 ...
- UIView 属性
1.alpha 设置视图的透明度.默认为1. ojbc // 完全透明 view.alpha = 0; // 不透明 view.alpha = 1; 2.clipsToBounds 默认是NO,当设置 ...
- 对List对象按照某个成员变量进行排序
/** * 对List对象按照某个成员变量进行排序 * @param list List对象 * @param sortField 排序的属性名称 * @param sortMode 排序方式:ASC ...
- linux创建用户和组
linux下创建用户(一) Linux 系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统.用户的账号一方面可以帮助系 ...
- cmd正常启动tomcat,而 从eclipse启动出现 404
设置Tomcat的路径,启动Tomcat,先测试一下环境,在浏览器中输入http://127.0.0.1:8080/ 提示 404找不到网页.出现这种问题然后试了一下,tomcat在外面直接启动 然 ...
- InterviewProblems
package com.xiaoysec; /** * 下面是面试趣医网技术面的时候出现的一个简单的题目 题目的要求是将一个数组中的奇数和偶数进行分离 以奇数在前一部分为例进行解题 * 算法的主要思想 ...
- MySQL管理一些基础SQL语句
.进入information_schema 数据库(存放了其他的数据库的信息) use information_schema; .查询所有数据的大小: ),),'MB') as data from i ...
- svn服务器配置小记
在这里/opt/svndata/repos1创建svn版本库svnadmin create /opt/svndata/repos1 创建成功后会在/opt/svndata/repos1目录下生成con ...
- Swift 控制流
Swift 1,顺序结构 2,分支结构 switch 中每一个case块完成后会自动终止switch语句, 不用手动终止 case 可有多值,如 case "A","a& ...
- Android 通知栏系列....
转:http://blog.csdn.net/vipzjyno1/article/details/25248021 在android的应用层中,涉及到很多应用框架,例如:Service框架,Activ ...