fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. // 定義一個結構體,表示二維坐標點
  5. typedef struct {
  6. int x, y;
  7. } Point;
  8.  
  9. int main() {
  10. // 讀取輸入的誤差值和總共的藏身點數量
  11. int err, n;
  12. scanf("%d", &err);
  13. scanf("%d", &n);
  14.  
  15. // 讀取目標點的坐標
  16. Point target, hide_sites[n];
  17. scanf("%d %d", &target.x, &target.y);
  18.  
  19. // 讀取所有藏身點的坐標
  20. for (int i = 0; i < n; ++i) {
  21. scanf("%d %d", &hide_sites[i].x, &hide_sites[i].y);
  22. }
  23.  
  24. // 初始化最小頭部誤差和頭部索引,最小軀幹誤差和軀幹索引
  25. int min_head_error = 1000;
  26. int head_index = -1;
  27. int min_torso_error = 1000;
  28. int torso_index1 = -1, torso_index2 = -1;
  29.  
  30. // 遍歷所有藏身點,計算與目標的距離,更新最小誤差和對應的索引
  31. for (int i = 0; i < n; ++i) {
  32. int distance_square = (hide_sites[i].x - target.x) * (hide_sites[i].x - target.x) +
  33. (hide_sites[i].y - target.y) * (hide_sites[i].y - target.y);
  34. int error = sqrt(distance_square);
  35.  
  36. // 更新最小頭部誤差和頭部索引
  37. if (error <= min_head_error) {
  38. min_head_error = error;
  39. head_index = i;
  40. }
  41.  
  42. // 更新最小軀幹誤差和軀幹索引
  43. if (error <= min_torso_error) {
  44. min_torso_error = error;
  45. torso_index2 = torso_index1;
  46. torso_index1 = i;
  47. }
  48. }
  49.  
  50. int error = 0;
  51. int target_width = 0;
  52.  
  53. // 根據最小誤差計算目標的寬度
  54. if (min_head_error <= 1000) {
  55. target_width = 15;
  56. } else if (min_torso_error <= 2000) {
  57. target_width = 35;
  58. }
  59.  
  60. // 計算誤差值
  61. if (target_width > 0) {
  62. error = (target_width * 100) / min_head_error;
  63. }
  64.  
  65. // 根據目標的寬度和誤差值輸出結果
  66. if (target_width == 15) {
  67. // 如果目標是頭部,輸出頭部的藏身點索引
  68. printf("%d\n", head_index);
  69. } else if (target_width == 35) {
  70. // 如果目標是軀幹,輸出兩個軀幹的藏身點索引
  71. printf("%d %d\n", torso_index1, torso_index2);
  72. } else {
  73. // 如果無法擊中目標,輸出 "abort"
  74. printf("abort\n");
  75. }
  76.  
  77. return 0;
  78. }
  79.  
Success #stdin #stdout 0s 5472KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
-1