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 = 2000 * err;
  11. int headIndex = -1;
  12. int torsoIndex1 = -1;
  13. int torsoIndex2 = -1;
  14. int minTorsoError = 2000 * err;
  15.  
  16. for (int i = 0; i < n; ++i) {
  17. int x, y;
  18. scanf("%d %d", &x, &y);
  19.  
  20. int distanceSquared = (x - Tx) * (x - Tx) + (y - Ty) * (y - Ty);
  21. int mils = (int)sqrt(distanceSquared) * 1000 / distanceSquared;
  22.  
  23. if (mils <= err) {
  24. int torsoError = (int)sqrt((x - Tx) * (x - Tx) + (y - Ty) * (y - Ty));
  25. if (torsoError <= err && torsoError < minTorsoError) {
  26. if (torsoIndex1 == -1) {
  27. torsoIndex1 = i;
  28. minTorsoError = torsoError;
  29. } else {
  30. torsoIndex2 = i;
  31. }
  32. }
  33. if (torsoError > err && mils < minHeadError) {
  34. headIndex = i;
  35. minHeadError = mils;
  36. }
  37. }
  38. }
  39.  
  40. if (headIndex != -1) {
  41. printf("%d\n", headIndex);
  42. } else if (torsoIndex1 != -1 && torsoIndex2 != -1) {
  43. printf("%d %d\n", torsoIndex1, torsoIndex2);
  44. } else {
  45. printf("abort\n");
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5460KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
0