fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int err, n, Tx, Ty;
  6. scanf("%d", &err);
  7. scanf("%d", &n);
  8. scanf("%d %d", &Tx, &Ty);
  9.  
  10. int minHeadError = 1000000;
  11. int minTorsoError = 1000000;
  12. int headIndex = -1, torsoIndex1 = -1, torsoIndex2 = -1;
  13.  
  14. for (int i = 0; i < n; ++i) {
  15. int x, y;
  16. scanf("%d %d", &x, &y);
  17. int distanceSquared = (x - Tx) * (x - Tx) + (y - Ty) * (y - Ty);
  18. int milError = sqrt(distanceSquared) * 1000 / 100; // convert to mils
  19.  
  20. int headWidth = 15 * 100; // 15 centimeters to millimeters
  21. int torsoWidth = 35 * 100; // 35 centimeters to millimeters
  22.  
  23. if (milError <= err) {
  24. if (2 * milError <= headWidth && milError < minHeadError) {
  25. minHeadError = milError;
  26. headIndex = i;
  27. } else if (2 * milError <= torsoWidth && milError < minTorsoError) {
  28. if (torsoIndex1 == -1) {
  29. torsoIndex1 = i;
  30. } else {
  31. torsoIndex2 = i;
  32. }
  33. minTorsoError = milError;
  34. }
  35. }
  36. }
  37.  
  38. if (headIndex != -1) {
  39. printf("%d", headIndex);
  40. } else if (torsoIndex1 != -1 && torsoIndex2 != -1) {
  41. if (torsoIndex1 < torsoIndex2) {
  42. printf("%d %d", torsoIndex1, torsoIndex2);
  43. } else {
  44. printf("%d %d", torsoIndex2, torsoIndex1);
  45. }
  46. } else {
  47. printf("abort");
  48. }
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 5392KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
abort