Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2016
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct point
  6. {
  7. long long x, y;
  8. point(){}
  9. point(long long x, long long y) : x(x), y(y) {}
  10. };
  11.  
  12. const long long INF = 2e+18 + 42;
  13. point a0, b0;
  14.  
  15. inline long long dist(point a, point b)
  16. {
  17. return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
  18. }
  19.  
  20. struct stcmp
  21. {
  22. bool operator() (point a, point b)
  23. {
  24. return dist(a, b0) > dist(b, b0);
  25. }
  26. };
  27.  
  28. inline bool cmpv(point a, point b)
  29. {
  30. return dist(a, a0) < dist(b, a0);
  31. }
  32.  
  33. int main()
  34. {
  35. ios_base::sync_with_stdio(false);
  36. set<point, stcmp> st;
  37. int n;
  38. cin >> n;
  39. cin >> a0.x >> a0.y >> b0.x >> b0.y;
  40. vector<point> v;
  41. for (int i = 0; i < n; i++)
  42. {
  43. point c;
  44. cin >> c.x >> c.y;
  45. v.push_back(c);
  46. st.insert(c);
  47. }
  48. sort(v.begin(), v.end(), cmpv);
  49. long long ans = dist(*st.begin(), b0);
  50. for (int i = 0; i < n; i++)
  51. {
  52. st.erase(v[i]);
  53. long long b_dist = 0;
  54. if (!st.empty())
  55. {
  56. b_dist = dist(*st.begin(), b0);
  57. }
  58. ans = min(ans, b_dist + dist(v[i], a0));
  59. }
  60. cout << ans;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement