Poj-2031-Building a Space Station-the shortest Circuit

Source: Internet
Author: User

Question: give you a few balls of the ball's heart and radius to establish a path between the balls. So that each ball can be directly or indirectly reached. Practice: regard each ball as a point, find the distance between each two points, and then generate the minimum tree algorithm., [Html] # include <iostream> # include <stdio. h> # include <string. h> # include <algorithm> # include <math. h ># define INF 99999999 using namespace std; struct list {double x; double y; double z; double r ;}point [100001]; double juli (int I, int j) {double len; len = sqrt (point [I]. x-point [j]. x) * (point [I]. x-point [j]. x) + (point [I]. y-point [j]. y) * (point [I]. y-point [j]. y) + (point [I]. z-point [j]. z) * (point [I]. z-point [J]. z); if (len-point [I]. r-point [j]. r <0) return 0; return len-point [I]. r-point [j]. r;} int main () {int I, j, n; double map [101] [101]; while (scanf ("% d", & n) {memset (map, 0, sizeof (map); for (I = 0; I <n; I ++) {cin> point [I]. x> point [I]. y> point [I]. z> point [I]. r ;}for (I = 0; I <n; I ++) {for (j = 0; j <n; j ++) {if (I! = J) {map [I] [j] = juli (I, j) ;}} double low [101]; int visit [101]; memset (visit, 0, sizeof (visit); visit [0] = 1; for (I = 0; I <n; I ++) {low [I] = map [0] [I];} double sum; sum = 0; for (I = 0; I <n; I ++) {double min; int ipos; min = INF; for (j = 0; j <n; j ++) {if (! Visit [j] & min> low [j]) {min = low [j]; ipos = j ;}} if (min = INF) break; sum + = min; visit [ipos] = 1; for (j = 0; j <n; j ++) {www.2cto.com if (low [j]> map [ipos] [j]) {www.2cto.com low [j] = map [ipos] [j] ;}} printf ("%. 3f \ n ", sum);} return 0 ;}

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.