fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. int x, y;
  6. } Point;
  7.  
  8. int main() {
  9. int err, n;
  10. scanf("%d", &err);
  11. scanf("%d", &n);
  12.  
  13. Point target, hide_sites[n];
  14. scanf("%d %d", &target.x, &target.y);
  15.  
  16. for (int i = 0; i < n; ++i) {
  17. scanf("%d %d", &hide_sites[i].x, &hide_sites[i].y);
  18. }
  19.  
  20. double angle_error = err * 0.001; // 將 err 轉換為角度誤差
  21. int min_head_error = 99999;
  22. int head_index = -1;
  23. int min_torso_error = 99999;
  24. int torso_index1 = -1, torso_index2 = -1;
  25.  
  26. for (int i = 0; i < n; ++i) {
  27. int distance_square = (hide_sites[i].x - target.x) * (hide_sites[i].x - target.x) +
  28. (hide_sites[i].y - target.y) * (hide_sites[i].y - target.y);
  29. double distance = sqrt(distance_square); // 距離
  30. double error = distance * angle_error; // 轉換為角度誤差
  31.  
  32. if (error <= min_head_error) {
  33. min_head_error = error;
  34. head_index = i;
  35. }
  36.  
  37. if (error <= min_torso_error) {
  38. min_torso_error = error;
  39. torso_index2 = torso_index1;
  40. torso_index1 = i;
  41. }
  42. }
  43.  
  44. int target_width = 0;
  45.  
  46. if (min_head_error <= 1000) {
  47. target_width = 15;
  48. } else if (min_torso_error <= 2000) {
  49. target_width = 35;
  50. }
  51.  
  52. int int_error = (int)round(min_head_error); // 四捨五入成最接近的整數
  53.  
  54. if (int_error <= target_width) {
  55. if (target_width == 15) {
  56. printf("%d\n", head_index);
  57. } else if (target_width == 35) {
  58. printf("%d %d\n", torso_index1, torso_index2);
  59. }
  60. } else {
  61. printf("abort\n");
  62. }
  63.  
  64. return 0;
  65. }
  66.  
Success #stdin #stdout 0.01s 5444KB
stdin
30
1
-104 5
339 820
stdout
abort