Last active
February 12, 2024 08:03
-
-
Save Starlight258/23073680b691efbdd78675e28158389c to your computer and use it in GitHub Desktop.
2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 김명지 | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.HashSet; | |
import java.util.Objects; | |
public class Main { | |
public static class Pair { | |
int x; | |
int y; | |
public Pair(int x, int y) { | |
this.x = x; | |
this.y = y; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) { | |
return true; | |
} | |
if (o == null || getClass() != o.getClass()) { | |
return false; | |
} | |
Pair pair = (Pair) o; | |
return x == pair.x && y == pair.y; | |
} | |
@Override | |
public int hashCode() { | |
return Objects.hash(x, y); | |
} | |
} | |
public static void main(String[] args) throws IOException { | |
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); | |
String[] input = bf.readLine().split(" "); | |
Pair piv = new Pair(Integer.parseInt(input[0]), Integer.parseInt(input[1])); | |
HashSet<Pair> set = new HashSet<>(); | |
for (int i = 0; i < 10; i++) { | |
input = bf.readLine().split(" "); | |
set.add(new Pair(Integer.parseInt(input[0]), Integer.parseInt(input[1]))); | |
} | |
int minDist = Integer.MAX_VALUE; | |
Pair minPair = piv; | |
for (Pair p : set) { | |
int dist = (int) (Math.pow(Math.abs(p.x - piv.x), 2) + Math.pow(Math.abs(p.y - piv.y), 2)); | |
if (dist < minDist) { | |
minDist = dist; | |
minPair = p; | |
} | |
} | |
System.out.println("(" + minPair.x + ", " + minPair.y + ")"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment