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 closestHeadIndex = -1;
  11. int closestTorsoIndex1 = -1;
  12. int closestTorsoIndex2 = -1;
  13. double minHeadDistance = 2000; // maximum possible distance
  14. double minTorsoDistance1 = 2000;
  15. double minTorsoDistance2 = 2000;
  16.  
  17. for (int i = 0; i < n; ++i) {
  18. int x, y;
  19. scanf("%d %d", &x, &y);
  20.  
  21. double distance = sqrt(pow(x - Tx, 2) + pow(y - Ty, 2));
  22. double error = distance * 1000; // convert distance to milliradians
  23.  
  24. if (error <= err && y >= Ty) {
  25. // hit in head
  26. if (distance < minHeadDistance) {
  27. minHeadDistance = distance;
  28. closestHeadIndex = i;
  29. }
  30. } else if (error <= err * 2 && y >= Ty) {
  31. // hit in torso
  32. if (distance < minTorsoDistance1) {
  33. minTorsoDistance2 = minTorsoDistance1;
  34. closestTorsoIndex2 = closestTorsoIndex1;
  35.  
  36. minTorsoDistance1 = distance;
  37. closestTorsoIndex1 = i;
  38. } else if (distance < minTorsoDistance2) {
  39. minTorsoDistance2 = distance;
  40. closestTorsoIndex2 = i;
  41. }
  42. }
  43. }
  44.  
  45. if (closestHeadIndex != -1) {
  46. // Found a hide site to hit in head
  47. printf("%d\n", closestHeadIndex);
  48. } else if (closestTorsoIndex1 != -1 && closestTorsoIndex2 != -1) {
  49. // Found two hide sites to hit in torso
  50. printf("%d %d\n", closestTorsoIndex1, closestTorsoIndex2);
  51. } else {
  52. // No suitable hide sites found
  53. printf("abort\n");
  54. }
  55.  
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 5476KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort