赞
踩
输入数据包括五行: 第一行为周围出租车打车点的个数n(1 ≤ n ≤ 50) 第二行为每个出租车打车点的横坐标tX[i] (-10000 ≤ tX[i] ≤ 10000) 第三行为每个出租车打车点的纵坐标tY[i] (-10000 ≤ tY[i] ≤ 10000) 第四行为办公室坐标gx,gy(-10000 ≤ gx,gy ≤ 10000),以空格分隔 第五行为走路时间walkTime(1 ≤ walkTime ≤ 1000)和taxiTime(1 ≤ taxiTime ≤ 1000),以空格分隔
输出一个整数表示,小易最快能赶到办公室的时间
2 -2 -2 0 -2 -4 -2 15 3
42
我的答案:- import java.awt.Point;
- import java.util.Scanner;
-
-
- public class Main {
-
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- Point taxi[] = new Point[n];
- for(int i=0;i<n;i++){
- taxi[i] = new Point();
- }
- for(int i=0;i<n;i++){
- int x = in.nextInt();
- taxi[i].x = x;
- }
- for(int i=0;i<n;i++){
- int y = in.nextInt();
- taxi[i].y = y;
- }
- int x = in.nextInt();
- int y = in.nextInt();
- Point end = new Point(x, y);
- Point start = new Point(0,0);
- int WalkSpeed = in.nextInt();
- int CarSpeed = in.nextInt();
- int walk_distance = Distance(start,end);
- int walk_time = walk_distance*WalkSpeed;
- int car_time = Integer.MAX_VALUE;
- for(int i=0;i<n;i++){
- int time = Distance(start,taxi[i])*WalkSpeed + Distance(end,taxi[i])*CarSpeed;
- if(time<car_time)
- car_time = time;
- }
- System.out.println(Math.min(walk_time, car_time));
- }
-
- private static int Distance(Point start, Point end) {
- return Math.abs(start.x-end.x)+Math.abs(start.y-end.y);
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。