-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day18p1.java
58 lines (53 loc) · 1.8 KB
/
Day18p1.java
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
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static Scanner sc = new Scanner(System.in);
public static PrintWriter out = new PrintWriter(System.out);
public static void solve() throws IOException {
String line;
long ans = 0;
int idx = 0;
int n = 784;
String[][] temp = new String[n][3];
while ((line = br.readLine()) != null) {
temp[idx] = line.split(" ");
idx++;
}
ArrayList<int[]> path = new ArrayList<>();
path.add(new int[]{0, 0});
int len = 0;
int[] curr = new int[]{0, 0};
for(String[] x : temp) {
if(x[0].equals("R")) {
curr[0] += Integer.parseInt(x[1]);
path.add(new int[]{curr[0], curr[1]});
} else if(x[0].equals("L")) {
curr[0] -= Integer.parseInt(x[1]);
path.add(new int[]{curr[0], curr[1]});
} else if(x[0].equals("U")) {
curr[1] -= Integer.parseInt(x[1]);
path.add(new int[]{curr[0], curr[1]});
} else if(x[0].equals("D")) {
curr[1] += Integer.parseInt(x[1]);
path.add(new int[]{curr[0], curr[1]});
}
len += Integer.parseInt(x[1]);
}
double area = 0;
path.add(new int[]{0, 0});
//shoelace
for(int i = 0; i < path.size()-1; i++) {
area += path.get(i)[0]*path.get(i+1)[1] - path.get(i+1)[0]*path.get(i)[1];
}
area /= 2.0;
//picks
out.println(area+1-(len)/2.0 + len);
}
public static void main (String[] args) throws IOException {
solve();
out.close();
}
}