HDU 4766 Network

题意   就是找到一个 位置 使得路由器可以覆盖所有英雄    可以不覆盖主人自己, 找到距离 主人房子最近的位置,距离为多少

没想到  其实是道水题啊!!  分三个情况讨论

第一个情况    如果  把主人的位置放上路由器 可以 覆盖到所有英雄,则答案出来了 0( 一个 半径为 d 的圆,边界上没有点);

第二个情况    考虑  圆上只有一个点,这个圆只受到该点的约束( 则圆心在  连线上);

第三个情况   两个点  或者更多点确定那个圆, 则当两个点或者更多的点都距离为d 时确定那个圆心;因为如果那个点的距离没有到d   证明我还可以更靠近一点房子

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<functional>
#define eps 1e-9
using namespace std;
const double PI = acos( -1.0 );
inline int dcmp( double x ){if( abs(x) < eps )return ;else return x<?-:;}
struct point{
double x,y;
point( double x = ,double y = ):x(x),y(y){}
}node[];
typedef point Vector;
typedef vector<point>ploygon;
inline point operator+( point a,point b ){ return point(a.x+b.x,a.y+b.y); }
inline point operator-( point a,point b ){ return point(a.x-b.x,a.y-b.y); }
inline point operator*( point a,double p){ return point(a.x*p,a.y*p); }
inline point operator/( point a,double p){ return point(a.x/p,a.y/p); }
inline bool operator< ( const point &a,const point &b ){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
inline bool operator==( const point &a,const point &b ){return (dcmp(a.x-b.x) == && dcmp(a.y-b.y) == );}
inline bool operator!=( const point &a,const point &b ){return a==b?false:true;} inline double Dot( point a,point b ){ return a.x*b.x + a.y*b.y; }
inline double Cross( point a,point b ){ return a.x*b.y - a.y*b.x; }
inline double Length( point a ){ return sqrt(Dot(a,a)); }
inline double Angle( point a,point b ){
double right = Dot(a,b)/Length(a)/Length(b);
return acos(right);
}
inline point Rotate( point a,double rad ){
return point( a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad+a.y*cos(rad)) );
}
point A[]; int N; double dis;
bool work( point temp )
{
for( int i = ; i <= N; i++ )
if( Length( A[i]-temp ) > dis && abs(Length( A[i] - temp ) - dis) > eps ){
return false;}
return true;
}
int main( )
{
//freopen( "ou.txt","r",stdin);
//freopen( "in.txt","w",stdout);
while( scanf("%lf%lf%lf",&A[].x,&A[].y,&dis) != EOF )
{
scanf("%d",&N);
for( int i = ; i <= N; i++ )
scanf("%lf%lf",&A[i].x,&A[i].y);
double Max = (<<); bool fell = false;
for( int i = ; i <= N; i++ )
if( Length( A[]-A[i] ) > dis )fell = true;
if( !fell ){ puts("0.00");continue;}
double Min = (<<);
for( int i = ; i <= N; i++ ){
point temp = A[i] + (A[] - A[i])*(dis/Length(A[]-A[i]));
if( Length( temp-A[] ) < Min ) if( work( temp ) )
Min = min( Min,Length(temp-A[]) );
}
for( int i = ; i <= N; i++ )
for( int j = i+; j <= N; j++ )
{
point temp = (A[i]+A[j])/2.0; double D = Length(A[i]-A[j])*0.5;
Vector now1 = Rotate( (A[i]-A[j]),PI/2.0 )*sqrt(dis*dis-D*D)/(D*2.0);
Vector now2 = Rotate( (A[i]-A[j]),-PI/2.0 )*sqrt(dis*dis-D*D)/(D*2.0);
point temp1 = temp + now1;
point temp2 = temp + now2;
if( Length( temp1-A[] ) < Min ) if( work( temp1 ) )
Min = min( Min,Length(temp1-A[]) );
if( Length( temp2-A[] ) < Min ) if( work( temp2 ) )
Min = min( Min,Length(temp2-A[]) );
}
if( Min == (<<) )puts("X");
else printf("%.2lf\n",Min);
}
return ;
}
/* 2600 10712 5075
1
26869 21003 */
上一篇:sql server cross/outer apply 用法


下一篇:初学python列表