Advertisement
a53

Harta3

a53
May 15th, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("harta3.in");
  4. ofstream fout("harta3.out");
  5. struct Points
  6. {
  7. double x,y;
  8. };
  9. Points V[101];
  10. const double inf=(1<<20)*1.0;
  11. int N,P[101];
  12. double A[101][101],S,minn;
  13.  
  14. double distance(Points A,Points B)
  15. {
  16. return sqrt(pow(B.x-A.x,2)+pow(B.y-A.y,2)*1.0);
  17. }
  18.  
  19. int main()
  20. {
  21. fin>>N;
  22. for(int i=1;i<=N;++i)
  23. fin>>V[i].x>>V[i].y;
  24. for(int i=1;i<=N;++i)
  25. for(int j=1;j<=N;++j)
  26. if(i!=j)
  27. A[i][j]=distance(V[i],V[j]);
  28. for(int i=2;i<=N;++i)
  29. P[i]=1;
  30. int nr=0;
  31. for(int k=1;k<N;++k)
  32. {
  33. minn=inf;
  34. for(int i=1;i<=N;++i)
  35. if(P[i]&&A[P[i]][i]<minn)
  36. minn=A[P[i]][i],nr=i;
  37. S+=A[P[nr]][nr];
  38. for(int i=1;i<=N;++i)
  39. if(P[i]&&A[P[i]][i]>A[i][nr])
  40. P[i]=nr;
  41. P[nr]=0;
  42. }
  43. fout<<fixed<<setprecision(4)<<S;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement