Guest User

Untitled

a guest
Oct 9th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. void solve() {
  2. // Test case #4
  3. n = 4;
  4. points = new ArrayList<>(n);
  5. points.add(new Point(1,-10000000));
  6. points.add(new Point(1, 10000000));
  7. points.add(new Point(10000000, -10000000));
  8. points.add(new Point(10000000, 10000000));
  9.  
  10. // This solution incorrectly returns "true"
  11. double r = 4.985E13;
  12. double x = 9765.625;
  13. io.println(acceptable(x,r));
  14. }
  15.  
  16. boolean acceptable(double x, double r) {
  17. double maxDistLeft = 0;
  18. double maxDistRight = 0;
  19. for (Point p : points) {
  20. double xDist = Math.abs((long)x - (long)p.x);
  21. double yDist = Math.abs((long)r - (long)p.y);
  22. double dist = Math.sqrt(xDist) * Math.sqrt(yDist) * Math.sqrt(xDist/yDist + yDist/xDist);
  23. if (p.x <= x) {
  24. maxDistLeft = max(maxDistLeft, dist);
  25. } else {
  26. maxDistRight = max(maxDistRight, dist);
  27. }
  28. }
  29. return (maxDistLeft <= r && maxDistRight <= r);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment