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, Tx, Ty;
  10. scanf("%d", &err);
  11. scanf("%d", &n);
  12. scanf("%d %d", &Tx, &Ty);
  13.  
  14. Point hideSites[n];
  15. for (int i = 0; i < n; ++i) {
  16. scanf("%d %d", &hideSites[i].x, &hideSites[i].y);
  17. }
  18.  
  19. int headIndex = -1;
  20. int torsoIndex1 = -1, torsoIndex2 = -1;
  21. int minHeadDistance = 2000 * 2000; // Maximum possible distance squared
  22. int minTorsoDistance = 2000 * 2000;
  23.  
  24. for (int i = 0; i < n; ++i) {
  25. int distanceSquared = (hideSites[i].x - Tx) * (hideSites[i].x - Tx) + (hideSites[i].y - Ty) * (hideSites[i].y - Ty);
  26.  
  27. // Check if the target falls within the head area
  28. if (distanceSquared <= (15 * 15 * 100 * 100) && distanceSquared < minHeadDistance) {
  29. headIndex = i;
  30. minHeadDistance = distanceSquared;
  31. }
  32.  
  33. // Check if the target falls within the torso area
  34. else if (distanceSquared <= (35 * 35 * 100 * 100) && distanceSquared < minTorsoDistance) {
  35. torsoIndex2 = torsoIndex1;
  36. torsoIndex1 = i;
  37. minTorsoDistance = distanceSquared;
  38. }
  39. }
  40.  
  41. if (headIndex != -1) {
  42. printf("%d", headIndex);
  43. } else if (torsoIndex1 != -1 && torsoIndex2 != -1) {
  44. printf("%d %d", torsoIndex1, torsoIndex2);
  45. } else {
  46. printf("abort");
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5460KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
1