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 */
HDU 4766 Network的更多相关文章
- HDU 2460 Network(双连通+树链剖分+线段树)
HDU 2460 Network 题目链接 题意:给定一个无向图,问每次增加一条边,问个图中还剩多少桥 思路:先双连通缩点,然后形成一棵树,每次增加一条边,相当于询问这两点路径上有多少条边,这个用树链 ...
- HDU 3078 Network(LCA dfs)
Network [题目链接]Network [题目类型]LCA dfs &题意: 给出n个点的权值,m条边,2种操作 0 u num,将第u个点的权值改成num k u v,询问u到v这条路上 ...
- HDU 2460 Network(桥+LCA)
http://acm.hdu.edu.cn/showproblem.php?pid=2460 题意:给出图,求每次增加一条边后图中桥的数量. 思路: 先用tarjan算法找出图中所有的桥,如果lowv ...
- HDU 2460 Network 傻逼Tarjan
Network Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2676 Network Wars 01分数规划,最小割 难度:4
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1676 对顶点i,j,起点s=1,终点t=n,可以认为题意要求一组01矩阵use ...
- HDU 3078 Network
简单的 RMQ: 先预处理得到 所有 节点的 公共祖先 和 dfs 得到所有节点的父亲节点: 然后 询问时,从自己出发向上找父亲, 然后 得到所有的节点:排序一下 不知道 这题这样也 ...
- HDU 3078 Network LCA
题意:n个点 m个询问,下面一行是n 个点的权值 再下面n-1行是双向的边 然后m个询问:k u v 若k==0,则把u点的权值改为v,否则回答u->v之间最短路经过点的权值中 第k大的值是多 ...
- hdu 3078 Network (暴力)+【LCA】
<题目链接> 题目大意:给定一颗带点权的树,进行两种操作,k=0,更改某一点的点权,k!=0,输出a~b路径之间权值第k大的点的点权. 解题分析:先通过RMQ的初始化,预处理pre[]数组 ...
- HDU 2460 Network 边双连通分量 缩点
题意: 给出一个无向连通图,有\(m\)次操作,每次在\(u, v\)之间加一条边,并输出此时图中桥的个数. 分析: 先找出边双连通分量然后缩点得到一棵树,树上的每条边都输原图中的桥,因此此时桥的个数 ...
随机推荐
- JS获取Url参数的通用方法
//获取URL中的参数 function request(paras) { var url = location.href.replace('#', ''); var paraString = url ...
- mysql limit
select * from tablename limit 1,4即取出第2条至第5条,4条记录
- return x>y?x:y ?:啥意思?
? :是一个三目运算符,先判断‘?’前面的,若为真,执行‘?’后面语句,else,执行‘:’后面语句! return (x>y?x:y) 即if(x>y) 执行xelse执行y
- C# DES 加密 解密
//注意:密钥必须为8位 private const string m_strEncryptKey = "abcd1234"; /// <summary> /// 加密 ...
- 2016CVTE编程题:兔子藏洞
兔子藏洞 题目描述 一只兔子藏身于20个圆形排列的洞中(洞从1开始编号),一只狼从x号洞开始找,下次隔一个洞找(及在x+2号洞找),在下次个两个洞找(及在x+5号洞找),以此类推...它找了n次仍然没 ...
- CentOS系统常用命令
1.进入目录命令 cd /usr/bin //进入etc目录 cd .. //切换到上一层目录 cd / //进入主目录 2.新建文件命令 比如进入某个目录后执行 vim test 2.查看运行的项目 ...
- FreePascal经典资料
------------------------------------------------------------------------ 这是每个版本的changelog: http://bu ...
- Adb connection Error:远程主机强迫关闭了一个现有的连接 解决方法
用真机调试程序的时候,eclipse 的 Console 总是出现如下的错误"Adb connection Error:远程主机强迫关闭了一个现有的连接". 问题出现的原因:这是 ...
- EXT实现表格斑马线
Ext.grid.GridPanel 单双行颜色样式(斑马线)2014-04-03 11:25 1078人阅读 评论(0) 收藏 举报分类:ExtJs(36)Ext.grid.GridPanel st ...
- SpringMVC + MyBatis 环境搭建(转)
本文转自:http://blog.csdn.net/zoutongyuan/article/details/41379851 源码地址:https://github.com/starzou/quick ...