Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Pr93 {
- public static void main(String ... args) throws FileNotFoundException {
- Scanner scan = new Scanner(new File("pr93.txt"));
- int p_count = scan.nextInt(), e_count = scan.nextInt();
- Map<String, Long> police = new HashMap<String, Long>();
- for (; p_count > 0; p_count--) {
- police.put(scan.next(), min(new int[] { scan.nextInt(),
- scan.nextInt() }));
- }
- long e;
- double min = Double.MAX_VALUE, dist;
- String best = "";
- for (; e_count > 0; e_count--) {
- e = min(new int[] { scan.nextInt(), scan.nextInt() });
- for (String p: police.keySet()) {
- dist = distance(e, police.get(p));
- if (dist < min) {
- best = p;
- min = dist;
- }
- }
- police.remove(best);
- System.out.println(best);
- }
- }
- public static int[] read(long pos) {
- return new int[] { (int)(-1 & pos)>>16, (int) (pos >> 16) };
- }
- public static long min(int[] parts) {
- return parts[0] << 16 | parts[1];
- }
- public static double distance(long a, long b) {
- int[] a_ = read(a), b_ = read(b);
- return Math.sqrt(Math.pow(a_[0] - b_[0], 2) + Math.pow(a_[1] - b_[1],
- 2));
- }
- }
Add Comment
Please, Sign In to add comment