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 ...
随机推荐
- 移动前端不得不了解的HTML5 head 头标签(2016最新版)
小编推荐:掘金是一个高质量的技术社区,从 ECMAScript 6 到 Vue.js,性能优化到开源类库,让你不错过前端开发的每一个技术干货.各大应用市场搜索「掘金」即可下载APP,技术干货尽在掌握. ...
- Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的适用版本
Jet 可以访问 Office 97-2003,但不能访问 Office 2007. ACE 既可以访问 Office 2007,也可以访问 Office 97-2003. 另外:Microsof ...
- C语言——strlen()和sizeof的区别
strlen()和sizeof()的区别: strlen()——>C字符串库函数,返回字符串的真实长度.它是从内存某位置开始扫描,直到碰到结束符'\0'停止,返回计数器值. sizeof()—— ...
- SQL Server中使用md5的方式
在SQl2005下自带的函数hashbytes() ,此函数是微软在SQL SERVER 2005中提供的,可以用来计算一个字符串的 MD5 和 SHA1 值,使用方法如下: --获取123456的M ...
- linux chmod使用说明
chmod是用来改变一个目录的访问权限的,一般的方式是:chmod a+rwx 其中a代表全部,还有u[目录拥有者] ,g[目录拥有组],o[其他用户] r代表读,w代表写,x代表可以执行,对应数字权 ...
- 使用runOnUiThread更新UI
android中更新UI的方式比较多,这里就不一一介绍了,比较常用的Thread+Handler,但是这种方式较繁琐,如在使用ProgressDialog创建进度对话框一文中就是使用的这种方式更新UI ...
- Atom power-mode
最近看到很多大牛都在用这个酷炫狂拽掉渣天的插件,于是就默默地git了一波.实际结果就是机械键盘加上砰砰砰砰,根本停不下来有没有. 建议(ˉ(∞)ˉ) :视力2.0的同学不建议使用,眼瞎的同学用就用吧, ...
- Activiti5 待审 待批任务 TaskQuery查询 条件查询 like查询
TaskQuery查询API 有两种方法可以从引擎中查询数据:查询API和原生查询.查询API提供了完全类型安全的API. 你可以为自己的查询条件添加很多条件 (所以条件都以AND组合)和精确的排序条 ...
- php正则的使用[替换,匹配]
// 隐藏电话的中间四位 echo parseMobile('15836365252'); function parseMobile($mobile, $start = 4, $len = 4){ $ ...
- 【java】for循环输出数字金字塔
输出下列数字金字塔. 1 121 123211234321 public class deng { public static void main(String args[]) { int n ...