java – GreetingCard problem with coordinates

This is a practice problem with Kattis

I have exceeded the deadline for the 5th of 11 test cases. Can someone inspire me how the code can be optimized?

Problem Description

Quido plans to send a greeting to his friend Hugo for the New Year. He has
He recently gained access to an advanced precision plotter and he
plans to print the greeting card on the plotter.

How the Plotter Works In the first step, the plotter draws one
complicated pattern of n Dots on the paper. In step two the picture
In the greeting, the plotter appears when it connects through a straight line
Segment every pair of points that is exact 2018 length units
a part.

The plotter uses a special holographic ink, which has a limited number
deliver. Quido wants the number of all drawn segments in the
Make sure there is enough ink to complete the job.

entrance

The first line contains a positive integer n indicating the value
Number of points drawn. The following n lines each contain a pair of
space-separated integer coordinates indicating a recorded point. Everyone
Coordinate is not negative and less than 2 ^ 31, There is at most
10 ^ 5 Points, all are different.

For this problem, all coordinates and distances are given in
Length of the plotter length, the length of the unit in x-direction and in
The Y direction is the same.

output

The output contains a single integer equal to the number of pairs of
Points that are accurate 2018 Length units apart.

sample receipt

``````4
20180000 20180000
20180000 20182018
20182018 20180000
20182018 20182018
``````

output

``````4
``````

Here is my code

``````import java.util. *;

Class Coordinates {
int x;
int y;

public coordinates (int x, int y) {
this.x = x;
this.y = y;
}

public double distanceWith (coordinates z) {
return Math.hypot ((x-z.x), (y-z.y));
}
}

Class greeting card {
public static void main (String [] args) {
Scanner sc = new scanner (System.in);
HashSet set = new HashSet <> ();
int count = sc.nextInt ();
int total = 0;
for (int i = 0; i <count; i ++) {
int x = sc.nextInt ();
int y = sc.nextInt ();
Coordinates curr = new coordinates (x, y);
if (i! = 0) {
total + = findDistances (curr, set);
}
}
System.out.println (total);
}

public static int findDistances (coordinates curr, HashSet to adjust) {
int total = 0;
for (coordinates inside: set) {
if (inside.distanceWith (curr) == 2018) {
total + = 1;
}
}
Total;
}
}
``````