The way of algorithmic problem netease small easy to return to the company fastest time

Source: Internet
Author: User
Tags abs min
Finally to the weekend. Small easy to walk in the streets of the city to find friends gathering, suddenly the server sent to alert, small easy to return to the company immediately to fix this urgent bug. Assuming the city is an infinitely large area, each street assumes the coordinates are (x, y), small easy to present on (0,0) streets, offices on (gx,gy) streets. Small easy around there are a number of taxi points, small easy to go to the office there are two options, one is to walk to the company, the other is to walk to a taxi point, and then from the location of the taxi to take a taxi to the company. Each move to an adjacent street (horizontal or vertical) will take walktime time to walk, and a taxi will take taxitime time. Small easy to get to the company as soon as possible, now small easy to know how quickly he needs to spend time to the company.
Input Description:


The input data includes five elements:


Number of taxi points around the first act n (1≤n≤50)


Second act the horizontal axis of each cab taxi point tx[i] ( -10000≤tx[i]≤10000)


The third act of each cab taxi point ordinate ty[i] ( -10000≤ty[i]≤10000)


Act IV Office coordinates gx,gy ( -10000≤gx,gy≤10000), separated by spaces


Act Five Walk Time Walktime (1≤walktime≤1000) and Taxitime (1≤taxitime≤1000), separated by spaces




Output Description:


Output an integer indicating that the small easy to get to the office time


Input Example:


2
-2-2
0-2
-4-2
15 3


Output Example:


42


See the topic, I think so, because to go to the company only two ways, one is walking, one is to a taxi to a taxi to the company, and there are several taxi points, so the calculation of each taxi point required time and walking time, where the minimum time is the final result.

You can iterate through a min function to get the minimum time to take a taxi, and then compare it with the walk time to get the final output.

public class Dache {public

	static void Main (string[] args) {
		//Get input from keyboard
		Scanner sc  = new Scanner (system.i n);
		int n = sc.nextint ();
		int[] tx = new Int[n];
		int[] ty = new Int[n];
		for (int i = 0; i < n; i++) {
			Tx[i] = Sc.nextint ();
		}
		for (int i = 0; i < n; i++) {
			Ty[i] = Sc.nextint ();
		}
		int GX = Sc.nextint ();
		int gy = Sc.nextint ();
		int walkt = Sc.nextint ();
		int taxit = Sc.nextint ();
		int drivet = Integer.max_value;
		int sumwalk = walkt* (Math.Abs (GX) +math.abs (GY)); This is the time to walk
		//Use the iteration method to get n the minimum time for a taxi point drivet for
		(int i = 0; i < n; i + +) {
			Drivet = math.min (walkt* (math.abs (Tx[i]) +math.abs (Ty[i]) +taxit* (Math.Abs (Gx-tx[i]) +math.abs (Gy-ty[i])), Drivet);
		}
		System.out.println (Math.min (Sumwalk, Drivet));  Taxi shortest time and walking time for comparison

	}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.