import java.io.*;
import java.util.*;
public class Main {
public static boolean isReflected(int[][] points) {
//find extremetis while making frequency map of points
HashMap<Long,Long> map = new HashMap<>();
long xmax = Integer.MIN_VALUE;
long xmin = Integer.MAX_VALUE;
for(int point[] : points){
long x = point[0];
long y = point[1];
xmax = Math.max(xmax , x);
xmin = Math.min(xmin , x);
//make a unique hash and store it against frequency
long hash = x * 100000000 + y; //constraint is 10^8
//we use L to convert it into long format
map.put(hash , 1L);
}
//find mirror between extremetis
long mirror = xmax + xmin;
for(int point[] : points){
long x = point[0];
long y = point[1];
//mirror point
long ximg = mirror - x;
//creating unique hash for mirror point
long hash_img = ximg * 100000000 + y;
//checking if mirror point exists
if(map.containsKey(hash_img) == false)
return false;
}
return true;
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[][] points = new int[n][2];
for (int i = 0; i < points.length; i++) {
for (int j = 0; j < points[0].length; j++) {
points[i][j] = scn.nextInt();
}
}
System.out.println(isReflected(points));
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter