# BZOJ 1052 覆盖问题

4
0 1
0 -1
1 0
-1 0

1

## HINT

 1 #include<vector>
2 #include<iostream>
3 #include<cstring>
4 #include<cstdio>
5 #include<cstdlib>
6 using namespace std;
7
8 #define inf (1<<29)
9 #define maxn 20010
10 int n,x[maxn],y[maxn]; bool exist[maxn];
11
12 inline bool dfs(int L,int step,int all)
13 {
14     if (all == n) return true;
15     if (step > 3) return false;
16     int up = -inf,down = inf,le = inf,ri = -inf;
17     for (int i = 1;i <= n;++i)
18         if (!exist[i])
19         {
20             up = max(y[i],up),down = min(y[i],down);
21             ri = max(x[i],ri),le = min(x[i],le);
22         }
23     int inc,nl,nr,nu,nd; vector <int> vec;
24     inc = 0; nl = le,nr = le+L,nu = up,nd = up-L;
25     for (int i = 1;i <= n;++i)
26         if (!exist[i] && x[i] >= nl&&x[i] <= nr&&y[i] >= nd&&y[i] <= nu)
27             ++inc,exist[i] = true,vec.push_back(i);
28     if (dfs(L,step+1,all+inc)) return true;
29     for (int i = 0;i < vec.size();++i) exist[vec[i]] = false; vec.clear();
30     inc = 0; nl = le,nr = le+L,nu = down+L,nd = down;
31     for (int i = 1;i <= n;++i)
32         if (!exist[i] && x[i] >= nl&&x[i] <= nr&&y[i] >= nd&&y[i] <= nu)
33             ++inc,exist[i] = true,vec.push_back(i);
34     if (dfs(L,step+1,all+inc)) return true;
35     for (int i = 0;i < vec.size();++i) exist[vec[i]] = false; vec.clear();
36     inc = 0; nl = ri-L,nr = ri,nu = up,nd = up-L;
37     for (int i = 1;i <= n;++i)
38         if (!exist[i] && x[i] >= nl&&x[i] <= nr&&y[i] >= nd&&y[i] <= nu)
39             ++inc,exist[i] = true,vec.push_back(i);
40     if (dfs(L,step+1,all+inc)) return true;
41     for (int i = 0;i < vec.size();++i) exist[vec[i]] = false; vec.clear();
42     inc = 0; nl = ri-L,nr = ri,nu = down+L,nd = down;
43     for (int i = 1;i <= n;++i)
44         if (!exist[i] && x[i] >= nl&&x[i] <= nr&&y[i] >= nd&&y[i] <= nu)
45             ++inc,exist[i] = true,vec.push_back(i);
46     if (dfs(L,step+1,all+inc)) return true;
47     for (int i = 0;i < vec.size();++i) exist[vec[i]] = false; vec.clear();
48     return false;
49 }
50
51 inline bool okay(int L)
52 {
53     memset(exist,false,n+1);
54     return dfs(L,1,0);
55 }
56
57 int main()
58 {
59     freopen("1052.in","r",stdin);
60     freopen("1052.out","w",stdout);
61     scanf("%d",&n); for (int i = 1;i <= n;++i) scanf("%d %d",&x[i],&y[i]);
62     if (okay(0)) printf("0"),exit(0);
63     int l = 1,r = inf,mid;
64     while (l <= r)
65     {
66         mid = (l + r) >> 1;
67         if (okay(mid)) r = mid - 1;
68         else l = mid + 1;
69     }
70     printf("%d",l);
71     fclose(stdin); fclose(stdout);
72     return 0;
73 }
View Code

posted @ 2015-02-10 18:25  lmxyy  阅读(81)  评论(0编辑  收藏