fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int err, n, Tx, Ty, min_head_index = -1, min_torso_index1 = -1, min_torso_index2 = -1;
  6. scanf("%d", &err);
  7. scanf("%d", &n);
  8. scanf("%d %d", &Tx, &Ty);
  9.  
  10. double min_head_distance = 2000000; // Initialize to a large value
  11. double min_torso_distance = 2000000;
  12.  
  13. for(int i = 0; i < n; ++i) {
  14. int xi, yi;
  15. scanf("%d %d", &xi, &yi);
  16.  
  17. double distance = sqrt(pow(xi - Tx, 2) + pow(yi - Ty, 2));
  18.  
  19. if (distance < err) {
  20. printf("%d\n", i);
  21. return 0;
  22. }
  23.  
  24. // Calculate the width of the torso target in mils
  25. double torso_width = atan(17.5 / distance) * 1000; // atan returns result in radians
  26.  
  27. if (torso_width < err && distance < min_torso_distance) {
  28. min_torso_distance = distance;
  29. min_torso_index1 = i;
  30. } else if (torso_width < err && distance >= min_torso_distance && distance < min_head_distance) {
  31. min_head_distance = distance;
  32. min_head_index = i;
  33. }
  34. }
  35.  
  36. if (min_torso_index1 != -1 && min_torso_index2 != -1) {
  37. printf("%d %d\n", min_torso_index1, min_torso_index2);
  38. } else if (min_head_index != -1) {
  39. printf("%d\n", min_head_index);
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5392KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
2