POJ 2420 A Star not a Tree? (Calculate geometry-Fermi point)

Source: Internet
Author: User

A Star not a Tree?

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3435 Accepted: 1724

Description

Luke wants to upgrade he home computer network from 10mbs to 100mbs. His existing network uses 10BASE2 (coaxial) cables, allow you to connect any number of computers together in a linear arrangement. Luke is particulary proud, he solved a nasty np-complete problem in order to minimize the total cable length.
Unfortunately, Luke cannot use his existing cabling. The 100mbs system uses 100baseT (twisted pair) cables. Each of the 100baseT cable connects only devices:either the network cards or a network card and a hub. (A hub is an electronic device, that interconnects several cables.) Luke has a choice:he can buy 2n-2 network cards and connect he N computers together by inserting one or more cards into Each computer and connecting them all together. Or He can buy N network cards and a hub and connect each of his n computers to the hub. The first approach would require that Luke configure he operating system to forward network traffic. However, with the installation of Winux 2007.2, Luke discovered that network forwarding no longer worked. He couldn ' t figure out what to re-enable forwarding, and he had never heard of Prim or Kruskal, so he settled on the second Approach:n network cards and a hub.

Luke lives in a lofts and so are prepared to run the cables and place the hub anywhere. But he won ' t move his computers. He wants to minimize the total length of cable he must buy.

Input

The first line of input contains a positive integer N <=, the number of computers. N lines follow; Each gives the (x, y) coordinates (in mm.) of a computer within the class. All coordinates is integers between 0 and 10,000.

Output

Output consists of one number, the total length of the cable segments, rounded to the nearest mm.

Sample Input

40 00 1000010000) 1000010000 0

Sample Output

28284

Source

Waterloo Local 2002.01.26

Main topic:

Find the Fermat point of the N-shaped edge. That is to find a point that makes the sum of the points to n points the smallest.


Problem Solving Ideas:

Triangles also have a fee for horse points. Triangle Fee The point is defined as: Look for a point within the triangle, so that the distance of three vertices to that point and the smallest.

The procedure for triangular fee-for-horse points is:

(1) If there is a corner greater than 120 degrees. Then the point at which this corner is located is the Fermi point.

(2) if not present. So for the triangle ABC, take two edges (if AB, AC), outward do equilateral triangle get C ' and A '. Then the intersection of AA ' and CC ' is the fee-for-horse point.


So for this n polygon, the strategy I took is completely different, using simulated annealing practice. This approach is relatively simple, but also can be used in the triangle to find the cost of the horse point.

The simulated annealing algorithm is the same as the adaptive algorithm in the numerical algorithm.

(1) Define the step size.

(2) Look for a starting point, in 8 directions to search by this step.

(3) Suppose to find a smaller point than the answer, then take this new point as the starting point, repeated (2)

(4) Assuming that there is no smaller point than the answer, then step by half, then try (2)

(5) Until the step size is less than the precision of the required answer stops.


Problem Solving Code:

#include <iostream> #include <cmath> #include <cstdio>using namespace Std;const int offx[]={1,1,0,-1,    -1,-1,0,1};const int Offy[]={0,1,1,1,0,-1,-1,-1};const int maxn=110;const double eps=1e-2;struct point{double x, y;    Point (double x0=0,double y0=0) {x=x0;y=y0;}    Double Getdis (point P) {return sqrt ((x-p.x) * (x-p.x) + (Y-P.Y) * (Y-P.Y));    }}p[maxn];int n;double getsum (point p0) {double sum=0;    for (int i=0;i<n;i++) Sum+=p0.getdis (P[i]); return sum;}    void Solve () {for (int i=0;i<n;i++) scanf ("%lf%lf", &p[i].x,&p[i].y);    Double Ans=getsum (p[0]), step=100;    Point S=p[0],d;        while (step>eps) {bool Flag=false;            for (int i=0;i<8;i++) {d=point (s.x+step*offx[i],s.y+step*offy[i]);            Double Tmp=getsum (d);                if (Tmp<ans) {s=d;                ans=tmp;            Flag=true;    }} if (!flag) step/=2; } printf ("%.0f\n", ans);} int main () {while (scanf ("%d", &n)!=eof) {solve (); } return 0;}




POJ 2420 A Star not a Tree? (Calculate geometry-Fermi point)

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.