1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include<iostream> #include<queue> #include<cmath> #include<cstdio> using namespace std; const long long maxn=1000005; const double INF=999999999; #define pp pair<double,int> #define mp make_pair int n,m; struct node { int nex,v; double val; }edge[maxn]; bool vis[maxn];int head[maxn],cnt; double dis[maxn]; double px[maxn],py[maxn]; void add(int u,int v,double val) { edge[++cnt].nex=head[u]; edge[cnt].val=val; edge[cnt].v=v; head[u]=cnt; } priority_queue<pp,vector<pp>,greater<pp> > q; void dij() { for(int i=1;i<=m+2;i++) dis[i]=INF; dis[m+1]=0; q.push(mp(0,m+1)); while(!q.empty()) { int u=q.top().second; q.pop(); if(vis[u]) continue; vis[u]=1; for(int i=head[u];i;i=edge[i].nex) { double val=edge[i].val; int v=edge[i].v; if(dis[v]>max(dis[u],val)) { dis[v]=max(dis[u],val); q.push(mp(dis[v],v)); } } } } double getdis(int x,int y) { return sqrt((px[x]-px[y])*(px[x]-px[y])+(py[x]-py[y])*(py[x]-py[y])); } int main() { cin>>n>>m; for(int i=1;i<=m;i++) { cin>>px[i]>>py[i]; add(m+1,i,px[i]); add(i,m+1,px[i]); add(m+2,i,double(n)-px[i]); add(i,m+2,double(n)-px[i]); } for(int i=1;i<=m;i++) { for(int j=i+1;j<=m;j++) { add(i,j,getdis(i,j)/2.0); add(j,i,getdis(i,j)/2.0); } } dij(); printf("%.2lf",dis[m+2]); }
|
近期评论