Network(计算几何:推规律+暴力+贪心)
来源:互联网 发布:高中信息技术vb教案 编辑:程序博客网 时间:2024/05/03 06:12
Link:http://acm.hdu.edu.cn/showproblem.php?pid=4766
Network
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 713 Accepted Submission(s): 171
Problem Description
With the help of the Ares L, the Emperor of Law and some stars of the future, General M succeeded in setting foot on the mountain, and had set up a kingdom, known as ACMSYSU. In order to reward these founding heroes, General M decided to share her network.
General M has manufactured a router. One can use this network if the Euclidean distance between his/her house and the router is not greater than d. Because of General M's excellent technology, the distance between her house and the router can be infinite.
There are n heroes in the kingdom besides General M. General M is not an eccentric person, so she hopes everyone can use the network. Because the farther the router is away from her house, the worse the signal, General M wants the router being as close to her house as possible. Please help General M place the router so that the distance between her house and the router is minimized, and every one can use the router. You just need to tell General M the minimum distance.
General M has manufactured a router. One can use this network if the Euclidean distance between his/her house and the router is not greater than d. Because of General M's excellent technology, the distance between her house and the router can be infinite.
There are n heroes in the kingdom besides General M. General M is not an eccentric person, so she hopes everyone can use the network. Because the farther the router is away from her house, the worse the signal, General M wants the router being as close to her house as possible. Please help General M place the router so that the distance between her house and the router is minimized, and every one can use the router. You just need to tell General M the minimum distance.
Input
The input will consist of multiple test cases.
For each case, the first line contains 3 integers x, y and d, which represent that the General M's house locates at the point (x, y) and one can use the network if his/her distance to the router is not greater than d.
The second line is a positive integer n, the number of heroes of the kingdom.
Then n lines follow. Each line has 2 integers x_i and y_i, indicating that the i-th hero locates at point (x_i, y_i)。
All integers in the input satisfy that their absolute values are less than or equal to 10^5, and 1<=n<=10^3.
For each case, the first line contains 3 integers x, y and d, which represent that the General M's house locates at the point (x, y) and one can use the network if his/her distance to the router is not greater than d.
The second line is a positive integer n, the number of heroes of the kingdom.
Then n lines follow. Each line has 2 integers x_i and y_i, indicating that the i-th hero locates at point (x_i, y_i)。
All integers in the input satisfy that their absolute values are less than or equal to 10^5, and 1<=n<=10^3.
Output
For each case, output a real number which indicates the minimum distance between the General M's house and the router, to two decimal places.
If it is impossible to share a network which can cover everyone, output an 'X' (without the single quote).
If it is impossible to share a network which can cover everyone, output an 'X' (without the single quote).
Sample Input
0 0 525 35 -30 0 125 35 -3
Sample Output
1.00X
Source
2013 ACM/ICPC Asia Regional Changchun Online
以下分析来自:http://www.cnblogs.com/wulangzhou/archive/2013/09/30/3346578.html
没想到 其实是道水题啊!! 分三个情况讨论:
第一个情况 如果 把主人的位置放上路由器 可以 覆盖到所有英雄,则答案出来了 0( 一个 半径为 d 的圆,边界上没有点);
第二个情况 考虑 圆上只有一个点,这个圆只受到该点的约束( 则圆心在 连线上);
第三个情况 两个点 或者更多点确定那个圆, 则当两个点或者更多的点都距离为d 时确定那个圆心;因为如果那个点的距离没有到d 证明我还可以更靠近一点房子
AC code:
#include<iostream>#include<cstring>#include<algorithm>#include<stdio.h>#include<cmath>#include<vector>#define eps 1e-9using namespace std;const double PI=acos( -1.0 );inline int dcmp( double x ){if( abs(x) < eps )return 0;else return x<0?-1:1;}struct point{ double x,y; point( double x = 0,double y = 0 ):x(x),y(y){}}node[112345];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) == 0 && dcmp(a.y-b.y) == 0);}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[1123]; int N; double dis;bool work( point temp ){ for( int i = 1; i <= N; i++ ) if( Length( A[i]-temp ) > dis && abs(Length( A[i] - temp ) - dis) > eps ){ return false;} return true;}int main(){while( scanf("%lf%lf%lf",&A[0].x,&A[0].y,&dis) !=EOF){scanf("%d",&N);for(int i=1;i<=N;i++){scanf("%lf%lf",&A[i].x,&A[i].y);}if(work(A[0])){ puts("0.00");}else{double Min=(1<<30);for(int i=1;i<=N;i++){point temp=A[i]+(A[0]-A[i])*(dis/Length(A[0]-A[i]));//圆心 if(Min>Length(temp-A[0])){if(work(temp)){Min=Length(temp-A[0]);}}}for(int i=1;i<=N;i++){for(int j=i+1;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);//过两点满足圆心与这两点距离为dis的圆心有两个 point temp1=temp+now1;point temp2=temp+now2; if( Length( temp1-A[0] ) < Min ){if( work( temp1 ) ){Min=Length( temp1-A[0] );}}if(Length( temp2-A[0] ) < Min){if( work( temp2 ) ){Min=Length( temp2-A[0] );}} }}if( Min==(1<<30) ) puts("X");else printf("%.2lf\n",Min);}}return 0;}
0 0
- Network(计算几何:推规律+暴力+贪心)
- hdu3902计算几何。。暴力
- nyoj 1078 汉诺塔(四)[二分图 || 规律 || 暴力 || 贪心]
- hdu 3952 计算几何 暴力
- FZU2148计算几何,暴力搜索
- HDU5533-计算几何|暴力-G
- HDU 5533(计算几何+暴力)
- HDU 4445(计算几何+暴力)
- hdu 6055 计算几何+暴力
- HDU 4454 Stealing a Cake(暴力计算几何)
- POJ1905 Expanding Rods(计算几何推公式+二分)
- HDU 4766 Network(计算几何 二分+三分)
- “玲珑杯”ACM比赛 Round #18 A -- 计算几何你瞎暴力(暴力)
- uva 1531 & poj 1518 Problem Bee(几何计算+贪心)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- 玲珑oj1143 计算几何你瞎暴力
- A 计算几何你瞎暴力
- Mac提示App已损坏 你应该将它移到废纸篓 解决方案
- git相关命令
- Gabor滤波入门
- Vmware Bridge联网设置
- Cocos2d 中使用聚合广告SDK
- Network(计算几何:推规律+暴力+贪心)
- Make a child component call his parent API in Polymer 1.0.0
- CYC-自定义导航栏去黑
- iOS CocoaPods的安装和使用详解
- 简单题_打印一个菱形
- 音频产品与视频、文字、图片产品的区别在哪里?
- SVN Attempted to lock an already-locked dir异常解决方法
- HTML5实现摇一摇的功能
- Core Graphics笔记