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. hideSites[i].distanceToHead = sqrt(pow(hideSites[i].x * 100 - Tx, 2) + pow(hideSites[i].y * 100 - Ty, 2) - 225) / 100.0; // 將距離轉換為m
  21. hideSites[i].distanceToTorso = sqrt(pow(hideSites[i].x * 100 - Tx, 2) + pow(hideSites[i].y * 100 - Ty, 2) - 1225) / 100.0; // 將距離轉換為m
  22. }
  23.  
  24. int headIndex = -1; // 初始化為-1
  25. int torsoIndex = -1; // 初始化為-1
  26.  
  27. for (int i = 0; i < n; ++i) {
  28. if (hideSites[i].distanceToHead <= err) {
  29. headIndex = i;
  30. break;
  31. } else if (hideSites[i].distanceToTorso <= err) {
  32. if (torsoIndex == -1) {
  33. torsoIndex = i;
  34. } else {
  35. // 如果已經找到一個軀幹射擊位置,則找到下一個軀幹射擊位置時,比較距離,選擇較近的位置
  36. if (hideSites[i].distanceToTorso < hideSites[torsoIndex].distanceToTorso) {
  37. torsoIndex = i;
  38. }
  39. }
  40. }
  41. }
  42.  
  43. if (headIndex != -1) {
  44. printf("%d\n", headIndex);
  45. } else if (torsoIndex != -1) {
  46. printf("%d %d\n", torsoIndex, headIndex); // 注意:這裡輸出的是軀幹射擊位置的索引和頭部射擊位置的索引
  47. } else {
  48. printf("abort\n");
  49. }
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5508KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort