fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. int x;
  6. int y;
  7. } Point;
  8.  
  9. int main() {
  10. int err, n;
  11. scanf("%d", &err);
  12. scanf("%d", &n);
  13.  
  14. int minHeadDistance = 2000; // maximum possible distance
  15. int minTorsoDistance = 2000; // maximum possible distance
  16. int headIndex = -1;
  17. int torsoIndex1 = -1;
  18. int torsoIndex2 = -1;
  19.  
  20. Point target, hide[n];
  21. scanf("%d %d", &target.x, &target.y);
  22.  
  23. for (int i = 0; i < n; ++i) {
  24. scanf("%d %d", &hide[i].x, &hide[i].y);
  25. int distanceSquared = (hide[i].x - target.x) * (hide[i].x - target.x) + (hide[i].y - target.y) * (hide[i].y - target.y);
  26. int distance = (int) sqrt(distanceSquared);
  27. int error = (distance * 100) / err;
  28.  
  29. if (error <= 100) { // accurate hit in head
  30. if (distance < minHeadDistance) {
  31. minHeadDistance = distance;
  32. headIndex = i;
  33. }
  34. } else if (error <= 200 && distance < minTorsoDistance) { // accurate hit in torso
  35. minTorsoDistance = distance;
  36. torsoIndex2 = torsoIndex1;
  37. torsoIndex1 = i;
  38. }
  39. }
  40.  
  41. if (headIndex != -1) {
  42. printf("%d", headIndex);
  43. } else if (torsoIndex1 != -1 && torsoIndex2 != -1) {
  44. if (torsoIndex1 < torsoIndex2) {
  45. printf("%d %d", torsoIndex1, torsoIndex2);
  46. } else {
  47. printf("%d %d", torsoIndex2, torsoIndex1);
  48. }
  49. } else {
  50. printf("abort");
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5444KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort