Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. bool sortbysec(const pair<double, double> &a,const pair<double,double> &b)
  5. {
  6. return (a.second < b.second);
  7. }
  8. int main()
  9. {
  10. int n;
  11. cin>>n;
  12. vector<pair<double,double> > v;
  13. for(int i=0; i<n; i++)
  14. {
  15. double x,y;
  16. cin>>x>>y;
  17. v.push_back(make_pair(x,y));
  18. }
  19. sort(v.begin(),v.end(), sortbysec);
  20.  
  21. double MIN=INT_MAX;
  22. for(int i=0; i<n; i++)
  23. {
  24. if(i<n-1)
  25. MIN=min(MIN,sqrt( ((v[i+1].first-v[i].first)*(v[i+1].first-v[i].first)) + ((v[i+1].second-v[i].second)*(v[i+1].second-v[i].second))));
  26. if(i==n-1)
  27. {
  28. MIN=min(MIN,sqrt( ((v[0].first-v[i+1].first)*(v[0].first-v[i+1].first)) + ((v[0].second-v[i+1].second)*(v[0].second-v[i+1].second))));
  29. }
  30. }
  31. cout<<fixed<<setprecision(2)<<MIN<<endl;
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement