Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Coor{
- double x, y;
- //double or else time limit exceeded
- bool operator<(const Coor &a) const{
- return x<a.x;
- }
- };
- int main(){
- //freopen("closestpairproblem.in", "r", stdin);
- int n;
- while(true){
- cin >> n;
- if(n == 0) return 0;
- vector<Coor> coor(n);
- for(int i=0; i<n; i++){
- cin >> coor[i].x >> coor[i].y;
- }
- sort(coor.begin(), coor.end());
- double mndist = INT_MAX;
- for(int i=0; i<n-1; i++){
- for(int j=i+1; j<n; j++){
- double dist;
- //cout << "coor[i].x: "<< coor[i].x << ", coor[i].y: " << coor[i].y
- //<< ", coor[j].x: " << coor[j].x << ", coor[j].y: " << coor[j].y << '\n';
- dist = (abs(coor[j].x-coor[i].x)*abs(coor[j].x-coor[i].x))
- +(abs(coor[j].y-coor[i].y)*abs(coor[j].y-coor[i].y));
- if(dist<mndist){
- mndist = dist;
- }
- }
- }
- double ans = sqrt(mndist);
- if(ans>10000){
- cout << "INFINITY" << '\n';
- }else{
- cout << fixed << setprecision(4) << ans << '\n';
- //fixed not just setprecision to 6 otherwise wrong answer
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement