# 【BZOJ】1052: [HAOI2007]覆盖问题

 1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<vector>
5 #include<cstdlib>
6 #include<cmath>
7 #include<cstring>
8 using namespace std;
9 #define maxn 100010
10 #define inf 0x7fffffff
11 #define llg int
12 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
13 llg n,m,lx,ly,rx,ry,mid;
14 bool bj[maxn],pd;
15
16 struct node
17 {
18     llg x,y;
19 }po[maxn];
20
21 void find_max()
22 {
23     lx=inf; ly=-inf;
24     rx=-inf; ry=inf;
25     for (llg i=1;i<=n;i++)
26         if (!bj[i])
27         {
28             lx=min(lx,po[i].x); rx=max(rx,po[i].x);
29             ly=max(ly,po[i].y); ry=min(ry,po[i].y);
30         }
31 }
32
33 void ss(llg cs)
34 {
35     if (pd) return ;
36     find_max();
37     llg LX=lx,LY=ly,RX=rx,RY=ry;
38     if (lx==inf) {pd=true; return ;}
39     if (cs>=4) return ;
40     for (llg k=1;k<=4;k++)
41     {
42         llg x,y;
43         if (k==1) x=LX,y=LY;
44         if (k==2) x=RX,y=RY;
45         if (k==3) x=LX,y=RY;
46         if (k==4) x=RX,y=LY;
47         vector<llg>c;
48         c.clear();
49         for (llg i=1;i<=n;i++)
50             if (abs(po[i].x-x)<=mid && abs(po[i].y-y)<=mid && !bj[i])
51             {
52                 bj[i]=1;
53                 c.push_back(i);
54             }
55         ss(cs+1);
56         llg w=c.size();
57         for (llg i=0;i<w;i++) bj[c[i]]=0;
58     }
59 }
60
61 bool check()
62 {
63     pd=false;
64     ss(1);
65     return pd;
66 }
67
68 int main()
69 {
70     yyj("bzoj1052");
71     cin>>n;
72     for (llg i=1;i<=n;i++) scanf("%d%d",&po[i].x,&po[i].y);
73     llg l=0,r=1e9,ans;
74     while (l<=r)
75     {
76         mid=(l+r)>>1;
77         if (check()) {r=mid-1; ans=mid;} else l=mid+1;
78     }
79     cout<<ans;
80     return 0;
81 }

posted @ 2017-03-07 09:12  №〓→龙光←  阅读(140)  评论(0编辑  收藏