Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. struct points
  8. {
  9.     ll x, y, dist1, dist2;
  10. };
  11.  
  12. bool compare (const points &a, const points &b)
  13. {
  14.     return a.dist1>b.dist1;
  15. }
  16.  
  17. int main ()
  18. {
  19.     ll r1=0, r2=0, i, j, k, l, n, x1, y1, x2, y2, ans, maxx=0, minn;
  20.     cin >> n >> x1 >> y1 >> x2 >> y2;
  21.     points a[n];
  22.     for (i=0; i<n; i++)
  23.     {
  24.         scanf("%lld %lld", &a[i].x, &a[i].y);
  25.         a[i].dist1 = (x1-a[i].x)*(x1-a[i].x) + (y1-a[i].y)*(y1-a[i].y);
  26.         a[i].dist2 = (x2-a[i].x)*(x2-a[i].x) + (y2-a[i].y)*(y2-a[i].y);
  27.     }
  28.     if (n==1)
  29.     {
  30.         ll x = (x1-a[0].x)*(x1-a[0].x) + (y1-a[0].y)*(y1-a[0].y);
  31.         ll b = (x2-a[0].x)*(x2-a[0].x) + (y2-a[0].y)*(y2-a[0].y);
  32.         cout << min(x, b);
  33.         return 0;
  34.     }
  35.     sort (a, a+n, compare);
  36.     ans = a[0].dist1;
  37.     r2=a[0].dist2;
  38.     r1=a[1].dist1;
  39.     for (i=1; i<n; i++)
  40.     {
  41.         r1=a[i].dist1;
  42.         if (a[i].dist1!=a[i-1].dist1)
  43.         {
  44.             for (j=1; j<i; j++)
  45.             {
  46.                 if (a[j].dist2>r2) r2=a[j].dist2;
  47.             }
  48.         }
  49.         if (r1+r2<ans)
  50.         {
  51.             ans=r1+r2;
  52.         }
  53.     }
  54.     cout << ans;
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement