Guest User

Untitled

a guest
May 16th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Pr93 {
  5. public static void main(String ... args) throws FileNotFoundException {
  6. Scanner scan = new Scanner(new File("pr93.txt"));
  7.  
  8. int p_count = scan.nextInt(), e_count = scan.nextInt();
  9.  
  10. Map<String, Long> police = new HashMap<String, Long>();
  11. for (; p_count > 0; p_count--) {
  12. police.put(scan.next(), min(new int[] { scan.nextInt(),
  13. scan.nextInt() }));
  14. }
  15.  
  16. long e;
  17. double min = Double.MAX_VALUE, dist;
  18. String best = "";
  19. for (; e_count > 0; e_count--) {
  20. e = min(new int[] { scan.nextInt(), scan.nextInt() });
  21.  
  22. for (String p: police.keySet()) {
  23. dist = distance(e, police.get(p));
  24. if (dist < min) {
  25. best = p;
  26. min = dist;
  27. }
  28. }
  29.  
  30. police.remove(best);
  31. System.out.println(best);
  32. }
  33. }
  34.  
  35. public static int[] read(long pos) {
  36. return new int[] { (int)(-1 & pos)>>16, (int) (pos >> 16) };
  37. }
  38.  
  39. public static long min(int[] parts) {
  40. return parts[0] << 16 | parts[1];
  41. }
  42.  
  43. public static double distance(long a, long b) {
  44. int[] a_ = read(a), b_ = read(b);
  45. return Math.sqrt(Math.pow(a_[0] - b_[0], 2) + Math.pow(a_[1] - b_[1],
  46. 2));
  47. }
  48. }
Add Comment
Please, Sign In to add comment