//GNC #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef vector array; typedef double base; typedef complex xy; typedef vector polygon; const double EPS=1.0e-12; #define LT(x,y) ((x)-(y)<-EPS) base innerProduct(xy p, xy q) { return real(conj(p)*q);} base outerProduct(xy p, xy q) { return imag(conj(p)*q);} int ccw(xy p1, xy p2, xy p3) { p2-=p1; p3-=p1; if ( LT(0,outerProduct(p2,p3)) ) return +1; if ( LT(outerProduct(p2,p3),0) ) return -1; if ( LT(p2.real()*p3.real(),0) || LT(p2.imag()*p3.imag(),0) ) return +2; if ( LT(norm(p2),norm(p3)) ) return -2; return 0; } bool intersect(xy p1, xy p2, xy p3, xy p4) { return (ccw(p1,p2,p3)*ccw(p1,p2,p4))<=0 && (ccw(p3,p4,p1)*ccw(p3,p4,p2))<=0; } typedef int point; typedef double weight; struct edge{ point dest; weight w; edge(){} edge(const point &dest, const weight &w):dest(dest),w(w){} }; bool operator>(const edge&lhs, const edge&rhs) { return LT(rhs.w,lhs.w); } typedef vector edges; typedef map graph; typedef map potential; potential dijkstra(graph &g, const vector &st) { potential pot; priority_queue > toBeProcessed; for ( int i=0 ; i0 ) return 1; if ( s==0 ) return 0; return -1; } graph polygon2graph(const polygon &po) { graph g; polygon v; for ( int i=0 ; i0 && sgn(outerProduct(tx-fx, po[from-1]-fx))*sgn(outerProduct(po[from+1]-fx,po[from-1]-fx))>0 && sgn(outerProduct(tx-fx, po[from+1]-fx))*sgn(outerProduct(po[from-1]-fx,po[from+1]-fx))>0 ) { continue; } if ( to0 && sgn(outerProduct(fx-tx, po[to+1]-tx))*sgn(outerProduct(po[to-1]-tx,po[to+1]-tx))>0 ) { continue; }*/ bool ok=true; for ( int i=0 ; i>nlines && nlines>0 ) { polygon po; for ( int i=0 ; i>x>>y; po.push_back(xy(x,y)); } graph g=polygon2graph(po); /* for ( graph::iterator it=g.begin() ;it!=g.end() ; ++it ) { cout<<"from "<<(it->first)/8 << ":" << (it->first)%8 << " "; edges &es=it->second; for ( int i=0 ; i st; for ( int i=0 ; i<8 ; i++ ) st.push_back(i); potential pot=dijkstra(g, st); cout.setf(ios::fixed); cout<0 ) m=min(m, pot[nlines*8-1-i]); } cout<