New game!
Https://www.nowcoder.com/acm/contest/201/L
Topic Description Eagle Jump is developing a new game. HiFuMi Takimoto, as one of the employees, was given the opportunity to play in advance. Now she is trying to pass a maze.
This maze has some features. To facilitate the description, we set up a planar Cartesian coordinate system for this maze. There are two parallel lines l1:ax+by+c1=0, l2:ax+by+c2=0, and n circles in the maze. Character in the straight line, circle, the garden walk does not consume energy. In other locations, the S-point goes to the T-point to consume the physical strength of s and T's Euclidean distance.
HiFuMi Takimoto want to start from L1, go to L2. Please calculate the minimum amount of physical energy required. Input Description:
First row five positive integers n,a,b,c
1
C
2
(1≤n≤1000, -10000≤a,b,c
1
C
2
≤10000), where a, b differs by 0.
The next n rows of three integers per line x,y,r ( -10000≤x,y≤10000, 1≤r≤10000) represent a circle with a circle (x, y) and a radius of R.
Output Description:
Only one line of a real number represents the answer. Absolute error or relative error not exceeding 10 with correct result
-4
Be counted correctly.
Input
2 0 1 0-40 1 11 3 1
Output
0.236068
You can think of a circle as a point, using the distance formula from point to line and the distance formula between points, to find out the distance between each point, run the shortest possible
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <stack>6#include <algorithm>7#include <cmath>8 #definePI ACOs (-1.0)9 #defineINF 0x3f3f3f3fTen using namespacestd; One A intN; - Doublea,b,c1,c2; - structcircle{ the DoubleX,y,r; -}p[1005]; - - Doublemap[1005][1005]; + Doublevis[1005]; - Doubledis[1005]; + A DoubleDist1 (Circle a,circle b) { at returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y))-a.r-B.R; - } - - DoubleDist2 (DoubleADoubleBDoublec,circle D) { - return(Fabs (A*d.x+b*d.y+c)/sqrt (a*a+b*b)-D.R); - } in - voidDijstra () { to for(intI=1; i<=n+2; i++){ +dis[i]=map[1][i]; -vis[i]=0; the } *vis[1]=1; $dis[1]=0;Panax Notoginseng for(intI=1; i<n+2; i++){ - Doubleminn=INF; the intpos=0; + for(intj=1; j<=n+2; j + +){ A if(!vis[j]&&dis[j]<Minn) { theminn=Dis[j]; +pos=J; - } $ } $vis[pos]=1; - for(intj=1; j<=n+2; j + +){ - if(!vis[j]&&dis[j]>minn+Map[pos][j]) { thedis[j]=minn+Map[pos][j]; - }Wuyi } the } -cout<<dis[n+2]<<Endl; Wu } - About intMain () { $Std::ios::sync_with_stdio (false); -Cin>>n>>a>>b>>c1>>C2; - for(intI=0;i<1005; i++){ - for(intj=0;j<1005; j + +){ Amap[i][j]=INF; + } the } - for(intI=2; i<=n+1; i++){ $Cin>>p[i].x>>p[i].y>>P[I].R; the } the Doubletmp; the for(intI=2; i<=n+1; i++){ the for(intj=i+1; j<=n+1; j + +){ -tmp=Dist1 (P[i],p[j]); in if(tmp>0) themap[i][j]=map[j][i]=tmp; the Else Aboutmap[i][j]=map[j][i]=0; the } the } the for(intI=2; i<=n+1; i++){ +tmp=Dist2 (A,b,c1,p[i]); - if(tmp>0) themap[1][i]=map[i][1]=tmp;Bayi Else themap[1][i]=map[i][1]=0; thetmp=Dist2 (A,b,c2,p[i]); - if(tmp>0) -map[n+2][i]=map[i][n+2]=tmp; the Else themap[n+2][i]=map[i][n+2]=0; the } themap[1][n+2]=map[n+2][1]=fabs (C1-C2)/sqrt (a*a+b*B); - Dijstra (); the the}
View Code
New game! (Shortest circuit + build)