|
| 1 | +import java.util.HashMap; |
| 2 | +import java.util.Iterator; |
| 3 | +import java.util.Map; |
| 4 | + |
| 5 | +/** |
| 6 | + * Created by LXF on 2017/8/11. |
| 7 | + */ |
| 8 | +public class Dche { |
| 9 | + public static int qTime(int taxiNum, int[] heng, int[] zong, Point gs, int wt, int tt) { |
| 10 | + |
| 11 | + HashMap<Point, Integer> taxi = new HashMap<Point, Integer>(); |
| 12 | + int n = heng.length; |
| 13 | + int zouLu = (Math.abs(gs.x) + Math.abs(gs.y)) * wt; |
| 14 | + if (n == 0) { |
| 15 | + return (wt > tt ? tt : wt) * (gs.x + gs.y); |
| 16 | + } |
| 17 | + for (int i = 0; i < n; i++) { |
| 18 | + Point point = new Point(heng[i], zong[i]); |
| 19 | + taxi.put(point, 0); |
| 20 | + } |
| 21 | + |
| 22 | + Iterator map = taxi.entrySet().iterator(); |
| 23 | + while (map.hasNext()) { |
| 24 | + Map.Entry entry = (Map.Entry) map.next(); |
| 25 | + Point point = (Point) entry.getKey(); |
| 26 | + int zouD = (Math.abs(point.x) + Math.abs(point.y)) * wt; |
| 27 | + int dacheD = Math.abs((gs.x-point.x) + Math.abs(gs.y-point.y)) * tt; |
| 28 | + entry.setValue(Math.min(zouLu, zouD + dacheD)); |
| 29 | + } |
| 30 | + int min = Integer.MAX_VALUE; |
| 31 | + Iterator iter = (Iterator) taxi.values(); |
| 32 | + while (iter.hasNext()) { |
| 33 | + int d = (int) iter.next(); |
| 34 | + min = Math.min(min, d); |
| 35 | + } |
| 36 | + return min; |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + static class Point{ |
| 41 | + int x; |
| 42 | + int y; |
| 43 | + |
| 44 | + public Point(int x, int y) { |
| 45 | + this.x = x; |
| 46 | + this.y = y; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + public static void main(String[] args) { |
| 51 | +// Scanner scanner = new Scanner(System.in); |
| 52 | +// int n = scanner.nextInt(); |
| 53 | +// String[] h = scanner.nextLine().toCharArray().toString().split(" "); |
| 54 | +// String[] z = scanner.nextLine().toCharArray().toString().split(" "); |
| 55 | +// int x = scanner.nextInt(); |
| 56 | +// int y = scanner.nextInt(); |
| 57 | + Point gs = new Point(-4, -2); |
| 58 | + int[] heng = new int[]{-2,-2}; |
| 59 | + int[] zong = new int[]{0,-2}; |
| 60 | +// |
| 61 | +// for (int i = 0;i<n;i++) { |
| 62 | +// heng[i] = Integer.parseInt(h[i]); |
| 63 | +// zong[i] = Integer.parseInt(z[i]); |
| 64 | +// } |
| 65 | +// int w = scanner.nextInt(); |
| 66 | +// int t = scanner.nextInt(); |
| 67 | + |
| 68 | + int n = 2; |
| 69 | + |
| 70 | + System.out.println(qTime(n, heng, zong, gs, 15, 3)); |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments