Advertisement
Emiliatan

a480

Feb 28th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. /* a480             */
  2. /* AC (0.2s, 7.7MB) */
  3. #include <cstdio>
  4. #include <algorithm>
  5. #define max(x,y) ((x)>(y)?(x):(y))
  6. #define min(x,y) ((x)<(y)?(x):(y))
  7.  
  8. using namespace std;
  9.  
  10. const int MAXN = 1000005, INF = 0x7f7f7f7f;
  11.  
  12. struct City
  13. {
  14.     int a, b;
  15. }city[MAXN];
  16.  
  17. int x1, y1, x2, y2, n, ans;
  18.  
  19. bool cmp(const City &i, const City &j)
  20. {
  21.     return i.a < j.a;
  22. }
  23.  
  24. int main()
  25. {
  26.     while(~scanf("%d %d", &x1, &y1))
  27.     {
  28.         ans = INF;
  29.         scanf("%d %d", &x2, &y2);
  30.  
  31.         scanf("%d", &n);
  32.         for(int i = 0, x, y; i < n && scanf("%d %d", &x, &y); i++)
  33.         {
  34.             city[i].a = (x - x1) * (x - x1) + (y - y1) * (y - y1);
  35.             city[i].b = (x - x2) * (x - x2) + (y - y2) * (y - y2);
  36.         }
  37.  
  38.         sort(city, city + n, cmp);
  39.  
  40.         for(int i = n - 2; i >= 0; i--)
  41.             city[i].b = max(city[i].b, city[i + 1].b);
  42.  
  43.         city[n].b = 0;
  44.         for(int i = 0; i < n; i++)
  45.             ans = min(ans, city[i].a + city[i + 1].b);
  46.  
  47.         printf("%d\n", min(ans, city[0].b));
  48.     }
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement