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, Tx, Ty;
  11. scanf("%d", &err);
  12. scanf("%d", &n);
  13. scanf("%d %d", &Tx, &Ty);
  14.  
  15. Point hideSites[n];
  16. for (int i = 0; i < n; ++i) {
  17. scanf("%d %d", &hideSites[i].x, &hideSites[i].y);
  18. }
  19.  
  20. int headIndex = -1;
  21. double minHeadDistance = 2000.0;
  22. int torsoIndices[2] = {-1, -1};
  23. double minTorsoDistances[2] = {2000.0, 2000.0};
  24.  
  25. for (int i = 0; i < n; ++i) {
  26. double distance = sqrt(pow(hideSites[i].x - Tx, 2) + pow(hideSites[i].y - Ty, 2)) / 100.0;
  27. double error = err / 100.0;
  28.  
  29. if (distance <= 1 + error) {
  30. // Sniper can hit the target in the head
  31. if (distance < minHeadDistance) {
  32. minHeadDistance = distance;
  33. headIndex = i;
  34. }
  35. } else if (distance <= 3 + error) {
  36. // Sniper can hit the target in the torso
  37. if (distance < minTorsoDistances[0]) {
  38. minTorsoDistances[1] = minTorsoDistances[0];
  39. minTorsoDistances[0] = distance;
  40. torsoIndices[1] = torsoIndices[0];
  41. torsoIndices[0] = i;
  42. } else if (distance < minTorsoDistances[1]) {
  43. minTorsoDistances[1] = distance;
  44. torsoIndices[1] = i;
  45. }
  46. }
  47. }
  48.  
  49. if (headIndex != -1) {
  50. printf("%d\n", headIndex);
  51. } else if (torsoIndices[0] != -1 && torsoIndices[1] != -1) {
  52. printf("%d %d\n", torsoIndices[0], torsoIndices[1]);
  53. } else {
  54. printf("abort\n");
  55. }
  56.  
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 5548KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort