Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution {
- public static int xStation;
- public static int yStation;
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- int N = in.nextInt();
- Gare[] gares = new Gare[N-1];
- int index = 0;
- for (int i = 0; i < N; i++)
- {
- String place = in.next();
- int X = in.nextInt();
- int Y = in.nextInt();
- if(place.equals("station"))
- {
- xStation = X;
- yStation = Y;
- }
- else
- gares[index++] = new Gare(place, X, Y);
- }
- Arrays.sort(gares, new GareComparator());
- String rep = "";
- for(Gare gare : gares)
- rep += gare.name + " ";
- System.out.println(rep.trim());
- }
- static class Gare
- {
- public String name;
- public int x;
- public int y;
- public Gare(String name, int x, int y)
- {
- this.name = name;
- this.x = x;
- this.y =y;
- }
- }
- public static class GareComparator implements Comparator<Gare>
- {
- @Override
- public int compare(Gare gare1, Gare gare2)
- {
- float gare1aStation = (gare1.x-xStation)*(gare1.x-xStation) + (gare1.y-yStation)*(gare1.y-yStation);
- float gare2aStation = (gare2.x-xStation)*(gare2.x-xStation) + (gare2.y-yStation)*(gare2.y-yStation);
- return new Float(gare1aStation).compareTo(new Float(gare2aStation));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement