-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDche.java
More file actions
73 lines (63 loc) · 2.15 KB
/
Dche.java
File metadata and controls
73 lines (63 loc) · 2.15 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
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Created by LXF on 2017/8/11.
*/
public class Dche {
public static int qTime(int taxiNum, int[] heng, int[] zong, Point gs, int wt, int tt) {
HashMap<Point, Integer> taxi = new HashMap<Point, Integer>();
int n = heng.length;
int zouLu = (Math.abs(gs.x) + Math.abs(gs.y)) * wt;
if (n == 0) {
return (wt > tt ? tt : wt) * (gs.x + gs.y);
}
for (int i = 0; i < n; i++) {
Point point = new Point(heng[i], zong[i]);
taxi.put(point, 0);
}
Iterator map = taxi.entrySet().iterator();
while (map.hasNext()) {
Map.Entry entry = (Map.Entry) map.next();
Point point = (Point) entry.getKey();
int zouD = (Math.abs(point.x) + Math.abs(point.y)) * wt;
int dacheD = Math.abs((gs.x-point.x) + Math.abs(gs.y-point.y)) * tt;
entry.setValue(Math.min(zouLu, zouD + dacheD));
}
int min = Integer.MAX_VALUE;
Iterator iter = (Iterator) taxi.values();
while (iter.hasNext()) {
int d = (int) iter.next();
min = Math.min(min, d);
}
return min;
}
static class Point{
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) {
// Scanner scanner = new Scanner(System.in);
// int n = scanner.nextInt();
// String[] h = scanner.nextLine().toCharArray().toString().split(" ");
// String[] z = scanner.nextLine().toCharArray().toString().split(" ");
// int x = scanner.nextInt();
// int y = scanner.nextInt();
Point gs = new Point(-4, -2);
int[] heng = new int[]{-2,-2};
int[] zong = new int[]{0,-2};
//
// for (int i = 0;i<n;i++) {
// heng[i] = Integer.parseInt(h[i]);
// zong[i] = Integer.parseInt(z[i]);
// }
// int w = scanner.nextInt();
// int t = scanner.nextInt();
int n = 2;
System.out.println(qTime(n, heng, zong, gs, 15, 3));
}
}