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, sites[n];
  14. scanf("%d %d", &target.x, &target.y);
  15.  
  16. int minHeadErr = 2000, minTorsoErr1 = 2000, minTorsoErr2 = 2000;
  17. int headIndex = -1, torsoIndex1 = -1, torsoIndex2 = -1;
  18.  
  19. for (int i = 0; i < n; ++i) {
  20. scanf("%d %d", &sites[i].x, &sites[i].y);
  21. int distanceSquared = (sites[i].x - target.x) * (sites[i].x - target.x) + (sites[i].y - target.y) * (sites[i].y - target.y);
  22. int errInCentimeters = sqrt(distanceSquared);
  23. int errInMils = errInCentimeters * 100 / 100000; // Convert to hundredths of a mil
  24.  
  25. if (errInMils <= err) {
  26. if (errInMils < minHeadErr) {
  27. minHeadErr = errInMils;
  28. headIndex = i;
  29. } else if (errInMils < minTorsoErr1) {
  30. minTorsoErr2 = minTorsoErr1;
  31. torsoIndex2 = torsoIndex1;
  32. minTorsoErr1 = errInMils;
  33. torsoIndex1 = i;
  34. } else if (errInMils < minTorsoErr2) {
  35. minTorsoErr2 = errInMils;
  36. torsoIndex2 = i;
  37. }
  38. }
  39. }
  40.  
  41. if (headIndex != -1) {
  42. printf("%d", headIndex);
  43. } else if (torsoIndex1 != -1 && torsoIndex2 != -1) {
  44. printf("%d %d", torsoIndex1, torsoIndex2);
  45. } else {
  46. printf("abort");
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5404KB
stdin
20
3
0 0
-500 1500
1000 200
3000 1000
stdout
Standard output is empty