BZOJ1946 : [Ceoi2006]ANTENNA

首先通过随机增量法求出最小覆盖圆,作为答案的上界。

然后二分答案,检验的时候枚举每个点作为原点,求出其他每个点被包括在圆内的角度区间,然后扫描线即可。

时间复杂度$O(Tn^2\log n)$。

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define N 510
using namespace std;
const double PI=acos(-1.0),eps=1e-8;
int n,K,i,j,k;double R,ansr,lim,l,r,mid;
struct P{
  double x,y;
  P(){}
  P(double _x,double _y){x=_x,y=_y;}
}a[N],O,anso;
struct E{
  double x;int t;
  E(){}
  E(double _x,int _t){x=_x,t=_t;}
}e[N<<2];
inline bool cmp(const E&a,const E&b){return a.x<b.x;}
inline double dis(const P&x,const P&y){
  return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}
inline P center(const P&x,const P&y,const P&z){
  double a1=y.x-x.x,b1=y.y-x.y,
         c1=(a1*a1+b1*b1)/2,a2=z.x-x.x,
         b2=z.y-x.y,c2=(a2*a2+b2*b2)/2,
         d=a1*b2-a2*b1;
  return P(x.x+(c1*b2-c2*b1)/d,x.y+(a1*c2-a2*c1)/d);
}
inline bool exist(int S,double R){
  int m=0;
  for(int i=0;i<n;i++)if(i!=S){
    if(dis(a[S],a[i])>R+R+eps)continue;
    double A=atan2(a[i].y-a[S].y,a[i].x-a[S].x),
           B=acos(dis(a[S],a[i])/(R+R));
    e[m++]=E(A-B,1);
    e[m++]=E(A+B,-1);
    e[m++]=E(A-B+PI*2,1);
    e[m++]=E(A+B+PI*2,-1);
  }
  sort(e,e+m,cmp);
  for(int i=0,ret=1;i<m;i++)if((ret+=e[i].t)==K){
    ansr=R;
    anso=P(a[S].x+cos(e[i].x)*R,a[S].y+sin(e[i].x)*R);
    return 1;
  }
  return 0;
}
inline bool check(double R){
  for(int i=0;i<n;i++)if(exist(i,R))return 1;
  return 0;
}
int main(){
  scanf("%d%d",&n,&K);
  for(i=0;i<n;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
  for(i=0;i<n;i++)swap(a[rand()%n],a[i]);
  for(O=a[0],i=1;i<n;i++)if(dis(a[i],O)>R+eps)
    for(O=a[i],R=0,j=0;j<i;j++)if(dis(a[j],O)>R+eps){
      O=P((a[i].x+a[j].x)/2,(a[i].y+a[j].y)/2),R=dis(a[i],O);
      for(k=0;k<j;k++)if(dis(a[k],O)>R+eps)O=center(a[k],a[j],a[i]),R=dis(a[i],O);
    }
  lim=ansr=R,anso=O;
  r=ansr-eps;
  while(l+eps<r){
    lim/=2;
    if(lim<1e-5)break;
    mid=(l+r)/2;
    if(check(mid))r=mid-eps;else l=mid+eps;
  }
  return printf("%.6f\n%.6f %.6f",ansr,anso.x,anso.y),0;
}

  

时间: 2024-12-25 07:52:30

BZOJ1946 : [Ceoi2006]ANTENNA的相关文章

POJ 3020 Antenna Placement 最大匹配

Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6445   Accepted: 3182 Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most st

POJ - 3020 Antenna Placement

Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It

poj 3020 Antenna Placement 解题报告

题目链接:http://poj.org/problem?id=3020 题目意思:首先,请忽略那幅有可能误导他人成分的截图(可能我悟性差,反正有一点点误导我了). 给出一幅 h * w 的图,  “ * ” 表示 point of interest,“ o ” 忽略之.你可以对 " * " (假设这个 “* ”的坐标是 (i, j))画圈,每个圈只能把它四周的某一个点括住(或者是上面(i-1, j) or 下面(i+1, j) or 左边(i, j-1)  or 右边(i, j+1))

POJ 3020 Antenna Placement ,二分图的最小路径覆盖

题目大意: 一个矩形中,有N个城市'*',现在这n个城市都要覆盖无线,若放置一个基站,那么它至多可以覆盖相邻的两个城市. 问至少放置多少个基站才能使得所有的城市都覆盖无线? 无向二分图的最小路径覆盖 = 顶点数 –  最大二分匹配数/2 路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且任何一个顶点有且只有一条路径与之关联: #include<cstdio> #include<cstring> #include<vector> #include<algor

Half Wavelength Dipole Antenna

Reference : 1. wikipedia   The dipole antenna is the simplest and most widely used class of antenna.It consists of two identical conductive elements such as metal wires or rods, which are usually bilaterally symmetrical.Each side of the feedline to t

POJ 3020 Antenna Placement(二分图建图训练 + 最小路径覆盖)

题目链接:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 3325 Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobi

POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)

Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6334   Accepted: 3125 Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most st

POJ——T 3020 Antenna Placement

http://poj.org/problem?id=3020 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9844   Accepted: 4868 Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden

Antenna Placement(匈牙利算法 ,最少路径覆盖)

Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6991   Accepted: 3466 Description The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most st