fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int err, n, Tx, Ty;
  6. scanf("%d", &err);
  7. scanf("%d", &n);
  8. scanf("%d %d", &Tx, &Ty);
  9.  
  10. int closest_head_index = -1;
  11. int torso_sites[2] = {-1, -1};
  12. int min_head_distance = 2000; // Max possible value as per constraints
  13. int min_torso_distance[2] = {2000, 2000};
  14.  
  15. for (int i = 0; i < n; ++i) {
  16. int xi, yi;
  17. scanf("%d %d", &xi, &yi);
  18. int distance_squared = (xi - Tx) * (xi - Tx) + (yi - Ty) * (yi - Ty);
  19.  
  20. // Check if the site is within the acceptable error for headshot
  21. if (sqrt(distance_squared) <= err * 0.01 * 1000 && distance_squared <= min_head_distance) {
  22. min_head_distance = distance_squared;
  23. closest_head_index = i;
  24. }
  25.  
  26. // Check if the site is within the acceptable error for torso shot
  27. if (sqrt(distance_squared) <= err * 0.01 * 1000) {
  28. // If the current site is closer than the existing torso sites, update the indices
  29. if (distance_squared <= min_torso_distance[0]) {
  30. min_torso_distance[1] = min_torso_distance[0];
  31. torso_sites[1] = torso_sites[0];
  32. min_torso_distance[0] = distance_squared;
  33. torso_sites[0] = i;
  34. } else if (distance_squared <= min_torso_distance[1]) {
  35. min_torso_distance[1] = distance_squared;
  36. torso_sites[1] = i;
  37. }
  38. }
  39. }
  40.  
  41. // Output the result based on conditions specified
  42. if (closest_head_index != -1) {
  43. printf("%d", closest_head_index);
  44. } else if (torso_sites[0] != -1 && torso_sites[1] != -1) {
  45. printf("%d %d", torso_sites[0], torso_sites[1]);
  46. } else {
  47. printf("abort");
  48. }
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5448KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort