hdu 3529 Bomberman - Just Search! 重复覆盖

题目链接

依然是重复覆盖的模板....

 #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, ans[maxn], sz, n, m;
void remove(int c) {
for(int i = D[c]; i!=c; i = D[i]) {
L[R[i]] = L[i];
R[L[i]] = R[i];
}
}
void resume(int c) {
for(int i = U[c]; i!=c; i = U[i]) {
L[R[i]] = i;
R[L[i]] = i;
}
}
int h() {
int cnt = ;
int vis[];
mem(vis);
for(int i = R[]; i!=; i = R[i]) {
if(!vis[i]) {
cnt++;
vis[i] = ;
for(int j = D[i]; j!=i; j = D[j]) {
for(int k = R[j]; k!=j; k = R[k]) {
vis[col[k]] = ;
}
}
}
}
return cnt;
}
void dfs(int d) {
if(d+h()>=deep)
return ;
if(R[] == ) {
deep = min(deep, d);
return ;
}
int c = R[];
for(int i = R[]; i!=; i = R[i])
if(S[c]>S[i])
c = i;
for(int i = D[c]; i!=c; i = D[i]) {
remove(i);
for(int j = R[i]; j!=i; j = R[j])
remove(j);
dfs(d+);
for(int j = L[i]; j!=i; j = L[j])
resume(j);
resume(i);
}
return ;
}
void add(int r, int c) {
sz++;
row[sz] = r;
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);
deep = inf;
for(int i = ; i<=n; i++) {
R[i] = i+;
L[i] = i-;
U[i] = i;
D[i] = i;
}
mem(S);
R[n] = ;
L[] = n;
sz = n;
}
int gra[][];
void solve() {
char g[][];
for(int i = ; i<n; i++) {
scanf("%s", g[i]);
}
int cnt = ;
for(int i = ; i<n; i++) {
for(int j = ; j<m; j++) {
if(g[i][j]=='*')
gra[i][j] = -;
if(g[i][j] == '.')
gra[i][j] = ;
if(g[i][j] == '#')
gra[i][j] = ++cnt;
}
}
int r = , tmp = n;
n = cnt;
init();
for(int i = ; i<tmp; i++) {
for(int j = ; j<m; j++) {
if(!gra[i][j]) {
r++;
for(int k = ; k<; k++) {
int tmpx = i, tmpy = j;
while() {
tmpx += dir[k][];
tmpy += dir[k][];
if(gra[tmpx][tmpy]) {
if(gra[tmpx][tmpy]>) {
add(r, gra[tmpx][tmpy]);
}
break;
}
}
}
}
}
}
dfs();
cout<<deep<<endl;
}
}dlx;
int main()
{
int n, m;
while(~scanf("%d%d", &dlx.n, &dlx.m)) {
dlx.solve();
}
return ;
}
上一篇:libevent安装


下一篇:hadoop笔记之Hive的数据存储(视图)