Transferred from: http://blog.csdn.net/jtjy568805874/article/details/51480479
#include <cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespaceStd;typedefLong LongLL;Const intn=1e6+5;Const intinf=0x3f3f3f3f;structnode{intL,r;} P[n];intn,m;BOOLJudgeintx) { intmn1=inf,mx1=-inf,mn2=inf,mx2=-INF; for(intI=0; i<m;++i) { if(p[i].r-p[i].l<=x)Continue; Mn1=min (mn1,p[i].l+p[i].r+x); MX1=max (mx1,p[i].l+p[i].r-x); Mn2=min (mn2,p[i].r-p[i].l+x); MX2=max (mx2,p[i].r-p[i].l-x); } if(MN1>=MX1&&MN2>=MX2)return true; return false;}intMain () { while(~SCANF ("%d%d",&n,&m)) { for(intI=0; i<m;++i) {scanf ("%d%d",&p[i].l,&P[I].R); if(p[i].l>p[i].r) Swap (P[I].L,P[I].R); } intL=0, r=N; while(l<R) { intMid= (l+r) >>1; if(Judge (mid)) r=mid; ElseL=mid+1; } printf ("%d\n", (L+r) >>1); } return 0;}
View Code
HDU 5699 Two-point determination of cargo transport