首页 技术 正文
技术 2022年11月14日
0 收藏 815 点赞 4,922 浏览 2553 个字

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

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

第一个情况    如果  把主人的位置放上路由器 可以 覆盖到所有英雄,则答案出来了 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 */
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727