fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. int x, y;
  6. } Point;
  7.  
  8. int main() {
  9. int err, n;
  10. scanf("%d", &err); // Read error tolerance
  11. scanf("%d", &n); // Read number of hide sites
  12.  
  13. Point target; // Read target coordinates
  14. scanf("%d %d", &target.x, &target.y);
  15.  
  16. Point hide_sites[n]; // Read hide site coordinates
  17. for (int i = 0; i < n; ++i) {
  18. scanf("%d %d", &hide_sites[i].x, &hide_sites[i].y);
  19. }
  20.  
  21. int best_hide_site = -1; // Initialize the best hide site index
  22. int min_error = 2000; // Initialize the minimum error to a value greater than the allowed error
  23.  
  24. // Iterate through hide sites and find the one with minimum error
  25. for (int i = 0; i < n; ++i) {
  26. int distance_squared = (hide_sites[i].x - target.x) * (hide_sites[i].x - target.x) +
  27. (hide_sites[i].y - target.y) * (hide_sites[i].y - target.y);
  28. int error = sqrt(distance_squared);
  29.  
  30. // If the error is within the allowed tolerance and less than the minimum error, update the best hide site
  31. if (error <= err && error < min_error) {
  32. min_error = error;
  33. best_hide_site = i;
  34. }
  35. }
  36.  
  37. // If a suitable hide site is found, print its index
  38. if (best_hide_site != -1) {
  39. printf("%d\n", best_hide_site);
  40. } else {
  41. // If no suitable hide site is found, print 'abort'
  42. printf("abort\n");
  43. }
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5424KB
stdin
18
11
1563588 1486379
1561768 1486652
1565578 1487883
1565323 1487671
1565478 1485701
1563789 1488357
1564975 1484728
1563807 1485864
1563187 1486786
1563547 1487697
1564567 1488194
1561796 1488193
stdout
abort