Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("harta3.in");
- ofstream fout("harta3.out");
- struct Points
- {
- double x,y;
- };
- Points V[101];
- const double inf=(1<<20)*1.0;
- int N,P[101];
- double A[101][101],S,minn;
- double distance(Points A,Points B)
- {
- return sqrt(pow(B.x-A.x,2)+pow(B.y-A.y,2)*1.0);
- }
- int main()
- {
- fin>>N;
- for(int i=1;i<=N;++i)
- fin>>V[i].x>>V[i].y;
- for(int i=1;i<=N;++i)
- for(int j=1;j<=N;++j)
- if(i!=j)
- A[i][j]=distance(V[i],V[j]);
- for(int i=2;i<=N;++i)
- P[i]=1;
- int nr=0;
- for(int k=1;k<N;++k)
- {
- minn=inf;
- for(int i=1;i<=N;++i)
- if(P[i]&&A[P[i]][i]<minn)
- minn=A[P[i]][i],nr=i;
- S+=A[P[nr]][nr];
- for(int i=1;i<=N;++i)
- if(P[i]&&A[P[i]][i]>A[i][nr])
- P[i]=nr;
- P[nr]=0;
- }
- fout<<fixed<<setprecision(4)<<S;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement