POJ 3525 Most Distant Point from the Sea
2013-08-22 19:50
337 查看
POJ 3525 Most Distant Point from the Sea
二分枚举最大长度。然后将半平面平移。
判断这些半平面是否有交。
二分枚举最大长度。然后将半平面平移。
判断这些半平面是否有交。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<deque> #include<queue> using namespace std; #define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--) #define oo 1e6 #define eps 1e-6 #define nMax 100000 #define pb push_back #define pf push_front #define F first #define S second #define bug puts("OOOOh....."); #define zero(x) (((x)>0?(x):-(x))<eps) #define LL long long #define DB double int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1; } class point { public: double x,y; point (double x=0,double y=0):x(x),y(y) {} void make(double _x,double _y) {x=_x;y=_y;} void read() { scanf("%lf%lf",&x,&y); } void out() { printf("%.2lf %.2lf\n",x,y);} double len() { return sqrt(x*x+y*y); } point friend operator - (point const& u,point const& v) { return point(u.x-v.x,u.y-v.y); } point friend operator + (point const& u,point const& v) { return point(u.x+v.x,u.y+v.y); } double friend operator * (point const& u,point const& v) { return u.x*v.y-u.y*v.x; } double friend operator ^ (point const& u,point const& v) { return u.x*v.x+u.y*v.y; } point friend operator * (point const& u,double const& k) { return point(u.x*k,u.y*k); } friend bool operator < (point const& u,point const& v){ if(dcmp(v.x-u.x)==0) return dcmp(u.y-v.y)<0; return dcmp(u.x-v.x)<0; } friend bool operator != (point const& u,point const& v){ return dcmp(u.x-v.x) || dcmp(u.y-v.y); } }; double const pi = acos(-1.0); typedef point vec; typedef class HalfPlane{ public: point P,a; vec V; double arg,len; HalfPlane(){}; HalfPlane(point a,point b):a(a){ V = b-a; arg = atan2(V.y,V.x); len = V.len(); } void forward(double l){ P = point(-V.y,V.x)*(l/len) + a; } } HP; double const inf = 1e5; deque<HP> que; deque<point> ans; vector<HP> init() { // Init while(!que.empty()) que.pop_back(); while(!ans.empty()) ans.pop_back(); vector<HP> ret;ret.clear(); ret.pb(HP(point(-inf,-inf),point(inf,-inf))); ret.pb(HP(point(inf,-inf),point(inf,inf))); ret.pb(HP(point(inf,inf),point(-inf,inf))); ret.pb(HP(point(-inf,inf),point(-inf,-inf))); return ret; } int satisfy(HP u, point a){ return dcmp(u.V*(a-u.P)) >= 0; } int cmp(HP a,HP b){ int ret = dcmp(a.arg-b.arg); if(ret == 0) return satisfy(b,a.P); return ret < 0; } int parrell(HP a,HP b){ return dcmp(a.V*b.V) == 0; } int same_dir(HP a,HP b){ return dcmp(a.V ^ b.V) >= 0; } int Same(HP a,HP b){ return (dcmp((a.P-b.P)*a.V)==0); } point Intersection(HP a,HP b){ point u = a.P-b.P; double t = (b.V*u)/(a.V*b.V); return a.P + a.V*t; } int erase_back(HP v){ while(ans.size() && !satisfy(v,ans.back())) { if(parrell(v,que.back())) return 0; ans.pop_back(); que.pop_back(); } return 1; } int erase_front(HP v){ while(ans.size() && !satisfy(v,ans.front())) { if(parrell(v,que.front())) return 0; ans.pop_front(); que.pop_front(); } return 1; } int add(HP v){ if(parrell(v,que.back())) return 0; // Can't Be such kind ans.push_back(Intersection(v,que.back())); que.pb(v); return 1; } void build(vector<HP>& hp){ vector<HP> Add =init(); for(int i=0;i<4;i++) hp.pb(Add[i]); } int HP_insection(vector<HP> hp,double l){ for(int i=0;i<(int)hp.size();i++) hp[i].forward(l); while(!que.empty()) que.pop_back(); while(!ans.empty()) ans.pop_back(); sort(hp.begin(),hp.end(),cmp); que.pb(hp[0]); for(int i=1;i<hp.size();i++) { if(dcmp(hp[i].arg - hp[i-1].arg)==0) continue; if(!erase_back(hp[i])) return 0; if(!erase_front(hp[i])) return 0;; if(!add(hp[i])) return 0; } while(ans.size() && !satisfy(que.front(),ans.back())){ ans.pop_back(); que.pop_back(); } while(ans.size() && !satisfy(que.back(),ans.front())) { ans.pop_front(); que.pop_front(); } if(!add(que.front())) return 0; return (int) ans.size() > 2; // return vector<point> (ans.begin(),ans.end()); // if you need; you would better use unique } vector<HP> v; int n; void sovle(){ double l=0.0,r=10000.0; double mid; double ret = 0.0; while(r-l>1e-7){ mid = (l+r)/2.0; if(HP_insection(v,mid)) { ret = max(ret,mid); l = mid; }else r=mid; } printf("%.6f\n",ret); } point p[nMax]; int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("D1.sol","w",stdout); #endif while(scanf("%d",&n),n){ // printf("n=%d\n",n); FOR(i,0,n-1) p[i].read(); v.clear(); p =p[0]; for(int i=0;i<n;i++) v.pb(HP(p[i],p[i+1])); // printf("%d\n",HP_insection(v,0.0)); // build(v);//printf("%d\n",v.size()); sovle(); } return 0; }
相关文章推荐
- poj 3525 Most Distant Point from the Sea
- POJ 3525: Most Distant Point from the Sea 半平面交 二分
- poj 3525 Most Distant Point from the Sea(多边形内最大圆)
- POJ 3525 Most Distant Point from the Sea
- POJ 3525 Most Distant Point from the Sea [半平面交 二分]
- poj 3525 Most Distant Point from the Sea(半平面交+二分)
- poj 3525 Most Distant Point from the Sea(二分+半平面交)
- POJ 3525 Most Distant Point from the Sea (banpingmianjiao)
- 【POJ】【3525】Most Distant Point from the Sea
- POJ 3525 Most Distant Point from the Sea
- POJ 3525 Most Distant Point from the Sea (半平面交+二分求最大内切圆)
- Poj 3525 Most Distant Point from the Sea (二分+半平面求交)
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
- POJ 3525 Most Distant Point from the Sea
- POJ3525 Most Distant Point from the Sea(半平面交)
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
- POJ 3525 Most Distant Point from the Sea(半平面交)
- poj 3525 Most Distant Point from the Sea
- POJ 3525 Most Distant Point from the Sea
- POJ 3525 Most Distant Point from the Sea 半平面交 +二分