The problem is to find the shortest path between two points, using the Dijkstra algorithm faster, ran 0.003s.
The method is simple, the circle as a node, directly determine whether two circles intersect, if the intersection distance is 0, otherwise the distance is the distance between the center minus the two circle radius. The start and end points can also be seen as a circle with a radius of 0.
This becomes the shortest-circuit problem between two points, which is suitable for solving with the Dijkstra algorithm. Comparison pit is the problem said the data range N Max 100, but I opened 105 unexpectedly re, as 505 on the past. So in the case of a small amount of memory, it is better to open up a bit.
See the code for details:
#include <bits/stdc++.h>using namespace Std;const double INF = 1000000000;const int MAXN = 505;int n,done[maxn],kase = 0;double D[MAXN];d ouble x,y,z,r;struct node{double x,y,z,r; Node (int x=0,int y=0,int z=0,int r=0): X (x), Y (y), Z (z), R (r) {}}a[maxn];struct Node {int from,to; Double D;} E[MAXN*MAXN];vector<int> g[maxn];struct heapnode{double D; int u; BOOL operator < (const heapnode& RHS) Const {return d > rhs.d; }};d ouble Dijkstra (int s) {priority_queue
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
1001-say Cheese (Dijkstra algorithm)