Advertisement
LADY_PLEASURER_2001

PRIMA s

May 20th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. using namespace std;
  5. const int INF = 1e9;
  6. struct Point{
  7. int x;
  8. int y;
  9. };
  10. double diistance(int x1, int y1, int x2, int y2){
  11. double a = x1;
  12. double b = x2;
  13. double c = y1;
  14. double d = y2;
  15. return sqrt(pow(a - b,2)/1.0 + pow(c - d,2)/1.0);
  16. }
  17.  
  18. int main() {
  19. int n;
  20. cin >> n;
  21. Point vertexes[5000];
  22. for (int i = 0; i < n; ++i){
  23. int x;
  24. int y;
  25. cin >> x >> y;
  26. Point a;
  27. a.x = x;
  28. a.y = y;
  29. vertexes[i] = a;
  30. }
  31. vector <double> d(n*(n-1)/2,INF);
  32. bool used[5000];
  33. int p[5000];
  34. for (int i = 0; i < 5000; ++i){
  35. used[i] = false;
  36. p[i] = -1;
  37. }
  38. d[0] = 0;
  39. int last_v;
  40. for (int i = 0; i < n; ++i){
  41. int v = -1;
  42. for (int j = 0; j < n - 1; ++j){
  43. if (!used[j] && (v == -1 || d[v] > d[j]))
  44. v = j;
  45. used[v] = true;
  46. for (int z = 0; z < n; ++z){
  47. int u = z;
  48. double w = diistance(vertexes[v].x,vertexes[v].y,vertexes[u].x,vertexes[u].y);
  49. if (!used[u] && d[u] > w && u!= v){
  50. d[u] = w;
  51. p[u] = v;
  52. last_v = u;
  53. cout << "Расстояние из вершины " << v << " в вершину " << u <<" равно " << w << endl;
  54. }
  55. }
  56. }
  57. }
  58. double summ = 0;
  59. for (int i = 0; i < n; ++i){
  60. cout << d[i] << endl;
  61. }
  62. cout << summ;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement