1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| #include<algorithm> #include<bitset> #include<complex> #include<deque> #include<exception> #include<fstream> #include<functional> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<iterator> #include<limits> #include<list> #include<locale> #include<map> #include<memory> #include<new> #include<numeric> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<typeinfo> #include<utility> #include<valarray> #include<vector> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<cmath> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> using namespace std;
#define re register #define It std::set<int>::iterator
class Quick_Input_Output{ private: static const int S=1<<21; char Rd[S],*A,*B; #define pc putchar public: #define gc getchar inline int read(){ int res=0,f=1;char ch=gc(); while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=gc();} while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=gc(); return res*f; } inline void write(int x){ if(x<0) pc('-'),x=-x; if(x<10) pc(x+'0'); else write(x/10),pc(x%10+'0'); } #undef gc #undef pc }I;
int n,vis[20010]; struct node{int x,y;}a[20010]; inline bool cmp(node qx,node qy){return qx.x<qy.x(qx.x==qy.x&&qx.y<qy.y);} inline bool dfs(int x,int L){ re int Minx=2e9,Maxx=-2e9,Miny=2e9,Maxy=-2e9; for(int i=1;i<=n;i++){ if(vis[i]==0){ Maxx=max(Maxx,a[i].x); Minx=min(Minx,a[i].x); Maxy=max(Maxy,a[i].y); Miny=min(Miny,a[i].y); } } re int lenx=Maxx-Minx,leny=Maxy-Miny; if(max(lenx,leny)<=L) return 1; if(x==3) return 0; for(int i=1;i<=n;i++){if(vis[i]==0&&Minx<=a[i].x&&a[i].x<=Minx+L&&Miny<=a[i].y&&a[i].y<=Miny+L) vis[i]=x;} if(dfs(x+1,L)) return 1; for(int i=1;i<=n;i++){if(vis[i]==x) vis[i]=0;} for(int i=1;i<=n;i++){if(vis[i]==0&&Maxx-L<=a[i].x&&a[i].x<=Maxx&&Miny<=a[i].y&&a[i].y<=Miny+L) vis[i]=x;} if(dfs(x+1,L)) return 1; for(int i=1;i<=n;i++){if(vis[i]==x) vis[i]=0;} for(int i=1;i<=n;i++){if(vis[i]==0&&Minx<=a[i].x&&a[i].x<=Minx+L&&Maxy-L<=a[i].y&&a[i].y<=Maxy) vis[i]=x;} if(dfs(x+1,L)) return 1; for(int i=1;i<=n;i++){if(vis[i]==x) vis[i]=0;} for(int i=1;i<=n;i++){if(vis[i]==0&&Maxx-L<=a[i].x&&a[i].x<=Maxx&&Maxy-L<=a[i].y&&a[i].y<=Maxy) vis[i]=x;} if(dfs(x+1,L)) return 1; for(int i=1;i<=n;i++){if(vis[i]==x) vis[i]=0;} return 0; } inline bool check(int x){memset(vis,0,sizeof(vis));return dfs(1,x);} signed main(){ n=I.read(); for(int i=1;i<=n;i++) a[i].x=I.read(),a[i].y=I.read(); sort(a+1,a+n+1,cmp); int l=0,r=2e9,ans=2e9; while(l<=r){ re int mid=l+r>>1; if(check(mid)) ans=mid,r=mid-1; else l=mid+1; } I.write(ans);putchar('\n'); return 0; }
|