Basic Java algorithm assistance

I need help writing a program that gives a specified number of coordinate points in the form of (x, y) The score to be given is the first line of the plan; It can be read in by scanner

I need x = A and y = B to calculate the minimum area covering all points Therefore, the area will be * B (rectangular area)

However, a coordinate point (x, y) must be removed to optimize the area The area of the removed points shall be as small as possible I need help writing algorithms to do this

This is an example input, and I get the output:

Sample input

four

2 4

1 1

5 2

17 25

Sample output

twelve

In this example, the first line of input (4) indicates that four points will be input The next four lines are the coordinates of the form (x, y) The last point (17,25) is removed as an outlier, leaving the first three points

If the remaining three points are graphs, they can all be in a box (3 by 4), so the output is 12; (3 * 4). This line works as in this example However, outliers are not always the last point, or very large Outliers can be very small, and the area only needs to be minimized

– this is me so far (I know it's not many...) – please help me!

It's mainly the algorithm I need help with

import java.io.*;
import java.util.*;

public class Area {

    public static void main(String args[]) {

        Scanner scan = new Scanner(system.in);

        int numOfPoints = scan.nextInt();
        int Xcoordinates[] = new int[numOfPoints];
        int Ycoordinates[] = new int[numOfPoints];


        for (int i = 0; i <= numOfCows - 1; i++) {
            Xcoordinates[i] = scan.nextInt();
            Ycoordinates[i] = scan.nextInt();
        }
    }
}

Possible pseudocode (continue from above; this may be wrong...):

for (int i = 0; i <= Xcoordinates.length; i++) { //loop through array 
     compare values,and determine outlier
     int lowestXValue = [find lowest x value]
     int highestXValue = [find highest x value; not outlier] }

     remove xcoordinates[outlier]
     remove ycoordinates[outlier]     

 int xLength = highestXValue - lowestXValue - 1 // -1 because can be on line

 for (int i = 0; i <= Ycoordinates.length; i++) { //loop through y array
      int lowestYValue = [find lowest y value]
      int highestYValue = [find highesy Y value] }

 int yLength = highestYValue - lowestYValue - 1;

 int @R_857_2419@Area = yLength * xLength

 System.out.println(@R_857_2419@Area);

However, this can only search for possible x outliers, and if there is a y value that can be deleted to minimize the area, it will not be captured

Solution

I'll create two integer sorted lists, one for X co ords and the other for y co ords You can then check the saved area by deleting the max X coordinate (the saved area should be the maximum coordinate time (maximum X coordinate – second highest X coordinate)) You can check the saved area by deleting the maximum coordinate, and the largest answer shall prevail

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>