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