-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldReduction.java
More file actions
65 lines (64 loc) · 1.78 KB
/
FieldReduction.java
File metadata and controls
65 lines (64 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.*;
import java.util.Arrays;
public class FieldReduction {
public static void main(String[] args) throws IOException
{
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("reduce.in"));
int N = Integer.parseInt(br.readLine());
int[][] points = new int[N][2];
int[] xvals = new int[N];
int[] yvals = new int[N];
String[] temp;
int x, y;
for (int i = 0; i < N; i++)
{
temp = br.readLine().split(" ");
x = Integer.parseInt(temp[0]);
y = Integer.parseInt(temp[1]);
points[i][0] = x;
points[i][1] = y;
xvals[i] = x;
yvals[i] = y;
}
Arrays.sort(xvals); Arrays.sort(yvals);
int[] lowX = new int[4]; int[] highX = new int[4];
int[] lowY = new int[4]; int[] highY = new int[4];
for (int i = 0; i < 4; i ++)
{
lowX[i] = xvals[i]; highX[i] = xvals[N-i-1];
lowY[i] = yvals[i]; highY[i] = yvals[N-i-1];
}
int count;
int xmin, xmax, ymin, ymax;
int min = Integer.MAX_VALUE;
for (int a = 0; a < 4; a++)
for (int b = 0; b < 4; b++)
for (int c = 0; c < 4; c++)
{
for (int d = 0; d< 4; d++)
{
count = 0;
xmin = Math.min(lowX[a], highX[b]); // may overlap
ymin = Math.min(lowY[c], highY[d]);
xmax = Math.max(lowX[a], highX[b]);
ymax = Math.max(lowY[c], highY[d]);
for (int i = 0; i < N; i++)
{
x = points[i][0]; y = points[i][1];
if (x < xmin || x > xmax || y < ymin || y > ymax)
count++;
}
if (count > 3)
continue;
if ((xmax-xmin)*(ymax-ymin) < min)
min = (xmax-xmin)*(ymax-ymin);
}
}
//System.out.println(min);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("reduce.out")));
pw.println(min);
pw.close();
br.close();
}
}