Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool sortbysec(const pair<double, double> &a,const pair<double,double> &b)
- {
- return (a.second < b.second);
- }
- int main()
- {
- int n;
- cin>>n;
- vector<pair<double,double> > v;
- for(int i=0; i<n; i++)
- {
- double x,y;
- cin>>x>>y;
- v.push_back(make_pair(x,y));
- }
- sort(v.begin(),v.end(), sortbysec);
- double MIN=INT_MAX;
- for(int i=0; i<n; i++)
- {
- if(i<n-1)
- 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))));
- if(i==n-1)
- {
- 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))));
- }
- }
- cout<<fixed<<setprecision(2)<<MIN<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement