fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. struct HideSite {
  5. int x, y;
  6. double distanceToHead;
  7. double distanceToTorso;
  8. };
  9.  
  10. int main() {
  11. int err, n, Tx, Ty;
  12. scanf("%d", &err);
  13. scanf("%d", &n);
  14. scanf("%d %d", &Tx, &Ty);
  15.  
  16. struct HideSite hideSites[n];
  17.  
  18. for (int i = 0; i < n; ++i) {
  19. scanf("%d %d", &hideSites[i].x, &hideSites[i].y);
  20. double distanceSquared = pow(hideSites[i].x - Tx, 2) + pow(hideSites[i].y - Ty, 2);
  21. hideSites[i].distanceToHead = sqrt(distanceSquared) - 0.15; // 考慮目標頭部尺寸
  22. hideSites[i].distanceToTorso = sqrt(distanceSquared) - 0.35; // 考慮目標軀幹尺寸
  23. }
  24.  
  25. int headIndex = -1;
  26. int torsoIndex1 = -1;
  27. int torsoIndex2 = -1;
  28.  
  29. for (int i = 0; i < n; ++i) {
  30. if (hideSites[i].distanceToHead <= err) {
  31. headIndex = i;
  32. break;
  33. } else if (torsoIndex1 == -1 && hideSites[i].distanceToTorso <= err) {
  34. torsoIndex1 = i;
  35. } else if (torsoIndex1 != -1 && hideSites[i].distanceToTorso <= err) {
  36. torsoIndex2 = i;
  37. break;
  38. }
  39. }
  40.  
  41. if (headIndex != -1) {
  42. printf("%d\n", headIndex);
  43. } else if (torsoIndex1 != -1 && torsoIndex2 != -1) {
  44. if (hideSites[torsoIndex1].distanceToTorso < hideSites[torsoIndex2].distanceToTorso) {
  45. printf("%d %d\n", torsoIndex1, torsoIndex2);
  46. } else {
  47. printf("%d %d\n", torsoIndex2, torsoIndex1);
  48. }
  49. } else {
  50. printf("abort\n");
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5540KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort