1001-say Cheese (Dijkstra algorithm)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.