POJ 2420 A Star not a Tree? Mountain Climbing algorithm

Source: Internet
Author: User

B-a Star not A Tree?

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88808#problem/B

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

4
0 0
0 10000
10000 10000
10000 0

Sample Output

28284

HINT

Test instructions

There are 100 points on the plane that allow you to find a point that makes these points to this point of distance and minimum

is to make you look for a broad-sense fee.

The following:

Mountain Climbing algorithm

There was a stupid rabbit, drunk, walking around, then sober, and then rolled back, that's it ...

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200051#defineMoD 10007#defineEPS 1e-9intNum;//const int INF=0X7FFFFFFF; //нчоч╢сConst intinf=0x3f3f3f3f; inline ll read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************intN;structnode{Doublex, y;};DoubleSqrDoublex) {    returnx*x;}DoubleDisDoubleXDoubleY,node P) {    returnsqrt (SQR (x-p.x) +sqr (yp.y));} Node p[ the];DoubleGet_sum (DoubleXDoubley) {    Doubleans=0;  for(intI=0; i<n;i++) {ans+=dis (x,y,p[i]); }    returnans;}intMain () {n=read ();  for(intI=0; i<n;i++) scanf ("%LF%LF",&p[i].x,&p[i].y);    Node ans; Ans.x=0, ans.y=0;  for(intI=0; i<n;i++) ans.x+=p[i].x,ans.y+=p[i].y; Ans.x= (ans.x/(n1.0)), ans.y= (ans.y/(n1.0)); DoubleAns =get_sum (ANS.X,ANS.Y); Doublet =10000; Doublex,y,tmp;  while(t>0.02) {x=0, y=0;  for(intI=0; i<n;i++) {x+ = (p[i].x-ans.x)/dis (ans.x,ans.y,p[i]); Y+ = (P[I].Y-ANS.Y)/dis (ans.x,ans.y,p[i]); } tmp= Get_sum (ans.x+x*t,ans.y+y*t); if(tmp<Ans) {Ans=tmp; Ans.x+=x*T; Ans.y+=y*T; } t*=0.9; } printf ("%.0lf\n", Ans);}

POJ 2420 A Star not a Tree? Mountain Climbing 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.