HDU 3845 凸包

来源:互联网 发布:关于网络诈骗的新闻 编辑:程序博客网 时间:2024/05/17 04:19
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<queue>#include<map>#include<set>using namespace std;#define mxn 1020#define inf 0x3f3f3f3f#define eps 1e-8#define LL long long #define ull unsigned long long#define MP make_pair#define For( i, x, y ) for( int i = x; i <= y; ++i )int zero( double x ) {if( fabs( x ) < eps )return 0;return x < 0 ? -1 : 1;}struct point{double x,y;void input() {scanf( "%lf%lf", &x, &y );}point() {}point( double _x, double _y ) {x = _x, y = _y;}double len() {return sqrt( x * x + y * y );}point operator - ( const point b ) const {return point( x - b.x, y - b.y );}point operator + ( const point b ) const {return point( x + b.x, y + b.y );}bool operator < ( const point b ) const {if(  zero( x - b.x ) )return x < b.x;return y < b.y;}}p[mxn], ch[mxn];double cross( point a, point b ) {return a.x * b.y - a.y * b.x;}double pnttoline( point a, point b, point c ) {double ret = fabs( cross( b - a, c - a ) );return ret / ( a - b ).len();}int n;int Ch() {int m = 0;For( i, 0, n - 1 ) {while( m > 1 && cross( ch[m-1] - ch[m-2], p[i] - ch[m-2] ) <= 0 )m--;ch[m++] = p[i];}int k = m;for( int i = n - 2; i >= 0; -- i ) {while( m > k && cross( ch[m-1]- ch[m-2], p[i] - ch[m-2] ) <= 0 )--m;ch[m++] = p[i];}if( n > 1 ) --m;return m;}int main() {int cas = 1;while( scanf( "%d", &n ) && n ) {For( i, 0, n - 1 )p[i].input();printf( "Case %d: ", cas++ );sort( p, p + n );int m = Ch();double mi = inf;For( i, 0, m - 2 ) {double ma = 0;For( j, 0, m - 1 ) {ma = max( ma, pnttoline( ch[i], ch[i+1], ch[j] ) );}mi = min( mi, ma );}double ma = 0;For( j, 0, m - 1 ) {ma = max( ma, pnttoline( ch[0], ch[m-1], ch[j] ) );}mi = min( mi, ma );printf( "%.2lf\n", mi );}return 0;}

0 0