四:半平面交
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; const double pi = acos ( - 1.0 ) ;
const double eps = 1e-5 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool cmp_Half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 1e3 + 10 ; Line que[ N] ; bool Half_lane_intersection ( vector< Line> & a) { sort ( a. begin ( ) , a. end ( ) , cmp_Half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; if ( tail - head < 3 ) return false ; return true ;
} int main ( ) { int T; scanf ( "%d" , & T) ; while ( T-- ) { int n; scanf ( "%d" , & n) ; vector< Point> res; for ( int i = 0 ; i < n; i++ ) { Point ans; ans. read ( ) ; res. push_back ( ans) ; } double area = Area ( res, n) ; vector< Line> a; if ( area > 0 ) { for ( int i = 0 ; i < n; i++ ) { a. push_back ( Line ( res[ i] , res[ ( i + 1 ) % n] ) ) ; } } else { for ( int i = n - 1 ; i >= 0 ; i-- ) { a. push_back ( Line ( res[ ( i + 1 ) % n] , res[ i] ) ) ; } } if ( Half_lane_intersection ( a) ) puts ( "YES" ) ; else puts ( "NO" ) ; } return 0 ;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; const double pi = acos ( - 1.0 ) ;
const double eps = 1e-5 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool cmp_Half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 1e3 + 10 ; Line que[ N] ; bool Half_lane_intersection ( vector< Line> & a) { sort ( a. begin ( ) , a. end ( ) , cmp_Half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; if ( tail - head < 3 ) return false ; return true ;
} int main ( ) { int n; while ( scanf ( "%d" , & n) && n) { vector< Point> res; for ( int i = 0 ; i < n; i++ ) { Point ans; ans. read ( ) ; res. push_back ( ans) ; } double area = Area ( res, n) ; vector< Line> a; if ( area > 0 ) { for ( int i = 0 ; i < n; i++ ) { a. push_back ( Line ( res[ i] , res[ ( i + 1 ) % n] ) ) ; } } else { for ( int i = n - 1 ; i >= 0 ; i-- ) { a. push_back ( Line ( res[ ( i + 1 ) % n] , res[ i] ) ) ; } } if ( Half_lane_intersection ( a) ) puts ( "1" ) ; else puts ( "0" ) ; } return 0 ;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; const double pi = acos ( - 1.0 ) ;
const double eps = 1e-5 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool cmp_Half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 1e3 + 10 ; Line que[ N] ; bool Half_lane_intersection ( vector< Line> & a) { sort ( a. begin ( ) , a. end ( ) , cmp_Half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; if ( tail - head < 3 ) return false ; return true ;
} int main ( ) { int n, cas = 1 ; while ( scanf ( "%d" , & n) && n) { vector< Point> res; for ( int i = 0 ; i < n; i++ ) { Point ans; ans. read ( ) ; res. push_back ( ans) ; } double area = Area ( res, n) ; vector< Line> a; if ( area > 0 ) { for ( int i = 0 ; i < n; i++ ) { a. push_back ( Line ( res[ i] , res[ ( i + 1 ) % n] ) ) ; } } else { for ( int i = n - 1 ; i >= 0 ; i-- ) { a. push_back ( Line ( res[ ( i + 1 ) % n] , res[ i] ) ) ; } } printf ( "Floor #%d\n" , cas++ ) ; if ( ! Half_lane_intersection ( a) ) puts ( "Surveillance is impossible." ) ; else puts ( "Surveillance is possible." ) ; puts ( "" ) ; } return 0 ;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; const double pi = acos ( - 1.0 ) ;
const double eps = 1e-5 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool Cmp_half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 1e4 + 10 ; Line que[ N] ; double Half_lane_intersection ( vector< Line> & a) { sort ( a. begin ( ) , a. end ( ) , Cmp_half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; n = tail - head; if ( n < 3 ) return 0 ; vector< Point> ans; for ( int i = head; i < tail; i++ ) { ans. push_back ( Intersect_point ( que[ i] , que[ ( i + 1 ) % n + head] ) ) ; } return Area ( ans, ans. size ( ) ) ;
} int main ( ) { int T, n; scanf ( "%d" , & T) ; while ( T-- ) { scanf ( "%d" , & n) ; vector< Point> res; for ( int i = 0 ; i < n; i++ ) { Point ans; ans. read ( ) ; res. push_back ( ans) ; } double area = Area ( res, n) ; vector< Line> a; if ( area > 0 ) { for ( int i = 0 ; i < n; i++ ) { a. push_back ( Line ( res[ i] , res[ ( i + 1 ) % n] ) ) ; } } else { for ( int i = n - 1 ; i >= 0 ; i-- ) { a. push_back ( Line ( res[ ( i + 1 ) % n] , res[ i] ) ) ; } } printf ( "%.2f\n" , Half_lane_intersection ( a) ) ; } return 0 ;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; const double pi = acos ( - 1.0 ) ;
const double eps = 1e-5 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool Cmp_half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 1e4 + 10 ; Line que[ N] ; bool Half_lane_intersection ( vector< Line> a, double x) { sort ( a. begin ( ) , a. end ( ) , Cmp_half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n; i++ ) { Vector dir = a[ i] . ed - a[ i] . st; dir = dir. Rotate ( pi / 2 ) ; double mod = dir. mod ( ) ; dir. x / = mod, dir. y / = mod; a[ i] . st = a[ i] . st + ( dir << x) ; a[ i] . ed = a[ i] . ed + ( dir << x) ; } for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; if ( tail - head < 3 ) return false ; return true ;
} int main ( ) { int T, n; while ( scanf ( "%d" , & n) && n) { vector< Point> res; for ( int i = 0 ; i < n; i++ ) { Point ans; ans. read ( ) ; res. push_back ( ans) ; } double area = Area ( res, n) ; vector< Line> a; if ( area > 0 ) { for ( int i = 0 ; i < n; i++ ) { a. push_back ( Line ( res[ i] , res[ ( i + 1 ) % n] ) ) ; } } else { for ( int i = n - 1 ; i >= 0 ; i-- ) { a. push_back ( Line ( res[ ( i + 1 ) % n] , res[ i] ) ) ; } } double l = 0 , r = 10000 ; for ( int i = 1 ; i <= 300 ; i++ ) { double mid = ( l + r) / 2 ; if ( Half_lane_intersection ( a, mid) ) l = mid; else r = mid; } printf ( "%.6f\n" , l) ; } return 0 ;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; const double pi = acos ( - 1.0 ) ;
const double eps = 1e-5 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool Cmp_half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 1e4 + 10 ; Line que[ N] ; void Half_lane_intersection ( vector< Line> a, double x) { sort ( a. begin ( ) , a. end ( ) , Cmp_half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n; i++ ) { Vector dir = a[ i] . ed - a[ i] . st; dir = dir. Rotate ( pi / 2 ) ; double mod = dir. mod ( ) ; dir. x / = mod, dir. y / = mod; a[ i] . st = a[ i] . st + ( dir << x) ; a[ i] . ed = a[ i] . ed + ( dir << x) ; } for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; n = tail - head; vector< Point> ans; for ( int i = head; i < tail; i++ ) { ans. push_back ( Intersect_point ( que[ i] , que[ ( i + 1 ) % n + head] ) ) ; } double dis = - 1 ; int fi = 0 , se = 0 ; n = ans. size ( ) ; for ( int i = 0 ; i < n; i++ ) { for ( int j = i + 1 ; j < n; j++ ) { double now = Dis_pp ( ans[ i] , ans[ j] ) ; if ( Sgn ( now - dis) > 0 ) { fi = i, se = j; dis = now; } } } if ( fabs ( ans[ fi] . x) < eps) ans[ fi] . x = 0 ; if ( fabs ( ans[ fi] . y) < eps) ans[ fi] . y = 0 ; if ( fabs ( ans[ se] . x) < eps) ans[ se] . x = 0 ; if ( fabs ( ans[ se] . y) < eps) ans[ se] . y = 0 ; printf ( "%.4f %.4f %.4f %.4f\n" , ans[ fi] . x, ans[ fi] . y, ans[ se] . x, ans[ se] . y) ;
} int main ( ) { int T, n; double r; while ( scanf ( "%d %lf" , & n, & r) != EOF ) { vector< Point> res; for ( int i = 0 ; i < n; i++ ) { Point ans; ans. read ( ) ; res. push_back ( ans) ; } double area = Area ( res, n) ; vector< Line> a; if ( area > 0 ) { for ( int i = 0 ; i < n; i++ ) { a. push_back ( Line ( res[ i] , res[ ( i + 1 ) % n] ) ) ; } } else { for ( int i = n - 1 ; i >= 0 ; i-- ) { a. push_back ( Line ( res[ ( i + 1 ) % n] , res[ i] ) ) ; } } Half_lane_intersection ( a, r) ; } return 0 ;
}
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream> using namespace std; #define double long double const double pi = acos ( - 1.0 ) ;
const double eps = 1e-10 ;
const double inf = 1e100 ; int Sgn ( double x) { return x < - eps ? - 1 : x > eps;
} struct Vector { double x, y; bool operator < ( Vector & a) const { return x < a. x; } void print ( ) { printf ( "%f %f\n" , x, y) ; } void read ( ) { scanf ( "%lf %lf" , & x, & y) ; } Vector ( double _x = 0 , double _y = 0 ) : x ( _x) , y ( _y) { } double mod ( ) { return sqrt ( x * x + y * y) ; } double mod2 ( ) { return x * x + y * y; } Vector operator + ( const Vector & a) { return Vector ( x + a. x, y + a. y) ; } Vector operator - ( const Vector & a) { return Vector ( x - a. x, y - a. y) ; } double operator * ( const Vector & a) { return x * a. x + y * a. y; } double operator ^ ( const Vector & a) { return x * a. y - y * a. x; } Vector Rotate ( double angle) { return Vector ( x * cos ( angle) - y * sin ( angle) , x * sin ( angle) + y * cos ( angle) ) ; } Vector operator << ( const double & a) { return Vector ( x * a, y * a) ; } Vector operator >> ( const double & a) { return Vector ( x / a, y / a) ; } bool operator == ( const Vector & a) { return ( Sgn ( x - a. x) == 0 ) && ( Sgn ( y - a. y) == 0 ) ; }
} ; typedef Vector Point; double Dis_pp ( Point a, Point b) { return sqrt ( ( a - b) * ( a - b) ) ;
} double Angle ( Vector a, Vector b) { double ans = atan2 ( a ^ b, a * b) ; return ans < 0 ? ans + 2 * pi : ans;
} double To_lefttest ( Point a, Point b, Point c) { return ( b - a) ^ ( c - a) ;
} int Toleft_test ( Point a, Point b, Point c) { return Sgn ( ( b - a) ^ ( c - a) ) ;
} struct Line { Point st, ed; Line ( Point _st = Point ( 0 , 0 ) , Point _ed = Point ( 0 , 0 ) ) : st ( _st) , ed ( _ed) { } bool operator < ( const Line & t) { return st. x < t. st. x; } void read ( ) { scanf ( "%lf %lf %lf %lf" , & st. x, & st. y, & ed. x, & ed. y) ; }
} ; bool Parallel ( Line a, Line b) { return Sgn ( ( a. st - a. ed) ^ ( b. st - b. ed) ) == 0 ;
} bool Is_cross ( Line a, Line b) { return Toleft_test ( a. st, a. ed, b. st) * Toleft_test ( a. st, a. ed, b. ed) <= 0 && Toleft_test ( b. st, b. ed, a. st) * Toleft_test ( b. st, b. ed, a. ed) <= 0 ;
} Point Cross_point ( Line a, Line b) { if ( ! Is_cross ( a, b) ) { return Point ( inf, inf) ; } else { double a1 = fabs ( To_lefttest ( a. st, a. ed, b. st) ) , a2 = fabs ( To_lefttest ( a. st, a. ed, b. ed) ) ; return ( ( b. st << a2) + ( b. ed << a1) ) >> ( a1 + a2) ; }
} Point Intersect_point ( Line a, Line b) { double a1 = a. st. y - a. ed. y, b1 = a. ed. x - a. st. x, c1 = a. st. x * a. ed. y - a. ed. x * a. st. y; double a2 = b. st. y - b. ed. y, b2 = b. ed. x - b. st. x, c2 = b. st. x * b. ed. y - b. ed. x * b. st. y; return Point ( ( c1 * b2 - c2 * b1) / ( a2 * b1 - a1 * b2) , ( a2 * c1 - a1 * c2) / ( a1 * b2 - a2 * b1) ) ;
} Point Shadow ( Line a, Point b) { Point dir = a. ed - a. st; return a. st + ( dir << ( ( ( b - a. st) * dir) / dir. mod2 ( ) ) ) ;
} Point Reflect ( Line a, Point b) { return ( Shadow ( a, b) << 2 ) - b;
} bool inmid ( double a, double b, double x) { if ( a > b) swap ( a, b) ; return Sgn ( x - a) >= 0 && Sgn ( b - x) >= 0 ;
} bool Point_in_line ( Line a, Point b) { if ( Toleft_test ( a. st, a. ed, b) != 0 ) return false ; return inmid ( a. st. x, a. ed. x, b. x) && inmid ( a. st. y, a. ed. y, b. y) ;
} double Dis_lp ( Line a, Point b) { Point h = Shadow ( a, b) ; if ( Point_in_line ( a, h) ) { return Dis_pp ( h, b) ; } return min ( Dis_pp ( a. st, b) , Dis_pp ( a. ed, b) ) ;
}
double Area ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = p[ i] ^ p[ ( i + 1 ) % n] ; } return 0.5 * ans;
} double Len ( vector< Point> p, int n) { double ans = 0 ; for ( int i = 0 ; i < n; i++ ) { ans + = Dis_pp ( p[ i] , p[ ( i + 1 ) % n] ) ; } return ans;
} bool Is_convex ( Point * a, int n) { bool flag[ 3 ] = { 0 , 0 , 0 } ; for ( int i = 0 ; i < n; i++ ) { flag[ Sgn ( To_lefttest ( a[ i] , a[ ( i + 1 ) % n] , a[ ( i + 2 ) % n] ) ) + 1 ] = true ; if ( flag[ 0 ] && flag[ 2 ] ) return false ; } return true ;
} Point p0; bool cmp_graham ( Point a, Point b) { int flag = Toleft_test ( p0, a, b) ; return flag == 0 ? Dis_pp ( p0, a) < Dis_pp ( p0, b) : flag > 0 ;
} vector< Point> Graham ( vector< Point> & a, int n) { p0 = a[ 0 ] ; for ( int i = 0 ; i < n; i++ ) { if ( a[ i] . y < p0. y || ( a[ i] . y == p0. y && a[ i] . x < p0. x) ) { p0 = a[ i] ; } } vector< Point> ans; sort ( a. begin ( ) , a. end ( ) , cmp_graham) ; if ( n == 1 ) { ans. push_back ( a[ 0 ] ) ; return ans; } if ( n == 2 ) { ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; return ans; } ans. push_back ( a[ 0 ] ) ; ans. push_back ( a[ 1 ] ) ; int sz = 2 ; for ( int i = 2 ; i < n; i++ ) { while ( sz > 1 && To_lefttest ( ans[ sz - 2 ] , ans[ sz - 1 ] , a[ i] ) <= 0 ) { ans. pop_back ( ) ; sz-- ; } ans. push_back ( a[ i] ) ; sz++ ; } return ans;
} bool cmp_andrew ( Point a, Point b) { if ( Sgn ( a. x - b. x) == 0 ) return a. y < b. y; return a. x < b. x;
} vector< Point> Andrew ( vector< Point> & a, int n) { sort ( a. begin ( ) , a. end ( ) , cmp_andrew) ; int p1 = 0 , p2; vector< Point> ans; for ( int i = 0 ; i < n; i++ ) { while ( p1 > 1 && Toleft_test ( ans[ p1 - 2 ] , ans[ p1 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p1-- ; ans. push_back ( a[ i] ) , p1++ ; } p2 = p1; for ( int i = n - 2 ; i>= 0 ; i-- ) { while ( p2 > p1 && Toleft_test ( ans[ p2 - 2 ] , ans[ p2 - 1 ] , a[ i] ) <= 0 ) ans. pop_back ( ) , p2-- ; ans. push_back ( a[ i] ) , p2++ ; } ans. pop_back ( ) ; return ans;
} double Get_angle ( Line a) { return atan2 ( a. ed. y - a. st. y, a. ed. x - a. st. x) ;
} bool Cmp_half_lane_intersection ( Line a, Line b) { Vector va = a. ed - a. st, vb = b. ed - b. st; double A = Get_angle ( va) , B = Get_angle ( vb) ; if ( Sgn ( A - B) == 0 ) return Sgn ( ( ( va) ^ ( b. ed - a. st) ) ) != - 1 ; return Sgn ( A - B) == - 1 ;
} bool On_right ( Line a, Line b, Line c) { Point o = Intersect_point ( b, c) ; if ( Sgn ( ( a. ed - a. st) ^ ( o - a. st) ) < 0 ) return true ; return false ;
} const int N = 2e4 + 10 ; Line que[ N] ; double Half_lane_intersection ( vector< Line> & a) { sort ( a. begin ( ) , a. end ( ) , Cmp_half_lane_intersection) ; int head = 0 , tail = 0 , cnt = 0 , n = a. size ( ) ; for ( int i = 0 ; i < n - 1 ; i++ ) { if ( Sgn ( Get_angle ( a[ i] ) - Get_angle ( a[ i + 1 ] ) ) == 0 ) continue ; a[ cnt++ ] = a[ i] ; } a[ cnt++ ] = a[ n - 1 ] ; for ( int i = 0 ; i < cnt; i++ ) { while ( tail - head > 1 && On_right ( a[ i] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( a[ i] , que[ head] , que[ head + 1 ] ) ) head++ ; que[ tail++ ] = a[ i] ; } while ( tail - head > 1 && On_right ( que[ head] , que[ tail - 1 ] , que[ tail - 2 ] ) ) tail-- ; while ( tail - head > 1 && On_right ( que[ tail - 1 ] , que[ head] , que[ head + 1 ] ) ) head++ ; n = tail - head; if ( n < 3 ) return 0 ; vector< Point> ans; for ( int i = head; i < tail; i++ ) { ans. push_back ( Intersect_point ( que[ i] , que[ ( i + 1 ) % n + head] ) ) ; } return Area ( ans, ans. size ( ) ) ;
} int main ( ) { int n; while ( scanf ( "%d" , & n) != EOF ) { vector< Line> ans; for ( int i = 1 ; i <= n; i++ ) { Line temp; temp. read ( ) ; ans. push_back ( temp) ; } ans. push_back ( Line ( Point ( 0 , 0 ) , Point ( 10000 , 0 ) ) ) ; ans. push_back ( Line ( Point ( 10000 , 0 ) , Point ( 10000 , 10000 ) ) ) ; ans. push_back ( Line ( Point ( 10000 , 10000 ) , Point ( 0 , 10000 ) ) ) ; ans. push_back ( Line ( Point ( 0 , 1000 ) , Point ( 0 , 0 ) ) ) ; printf ( "%.1lf\n" , Half_lane_intersection ( ans) ) ; } return 0 ;
}