-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain2.java
More file actions
81 lines (59 loc) · 1.71 KB
/
Main2.java
File metadata and controls
81 lines (59 loc) · 1.71 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package tencent;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main2 {
static class Node {
int nodeX;
int nodeY;
Node(int x, int y) {
this.nodeX = x;
this.nodeY = y;
}
int dist(int x0, int y0) {
int d_x = x0 - nodeX;
int d_y = y0 - nodeY;
int dist = Math.abs(d_x) + Math.abs(d_y);
return dist;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String first = in.nextLine();
int N = Integer.parseInt(first.split(" ")[0]);
int M = Integer.parseInt(first.split(" ")[1]);
List<Node> nodes = new ArrayList<>(N);
List<Node> starts = new ArrayList<>(M);
for (int i = 0; i < N; i++) {
String line = in.nextLine();
int x = Integer.parseInt(line.split(" ")[0]);
int y = Integer.parseInt(line.split(" ")[1]);
Node node = new Node(x, y);
nodes.add(node);
}
for (int i = 0; i < M; i++) {
String line = in.nextLine();
int x = Integer.parseInt(line.split(" ")[0]);
int y = Integer.parseInt(line.split(" ")[1]);
Node node = new Node(x, y);
starts.add(node);
}
in.close();
for (Node start : starts) {
int thisResult = 0;
for (Node node : nodes) {
int dist = node.dist(start.nodeX, start.nodeY);
thisResult += dist;
}
System.out.println(thisResult);
}
}
}
//3 3
//5 5
//5 10
//10 5
//1 1
//5 5
//10 10