Hdoj/hdu 2547 No Sword no Me (distance between two points)

Source: Internet
Author: User

Problem Description
In the late Northern Song Dynasty, Traitor Reign, eunuch in power, foreign aggression day, Liao Army recidivism. Nowadays, there are many wars, smoke four, depressed, hardship, and a large number of capable and anti-talented, the world's Patriots gathered response, landscape from.
On this desperate autumn, in an isolated place on the-mca Hill, a man in the lake called < Heroes where to come out > the person is to combat the Liao Thief Research Sword, and finally on a Thunder night accurate calculation of the sword back front of the swords gas damage formula.

Define f (x, Y, m, n) = sqrt (x*x + y*y + m*m + n*n-2*m*x-2*n*y);
HINT:SQRT denotes a radical, i.e. sqrt (4) = 2; sqrt (16) = 4;

(where x, Y is a positional variable, m,n is a property constant)
Sword Air damage = f (x, Y, A, B) + f (x, Y, C, D);
The sword is so powerful that it's hard to control, and now he wants to know the minimum damage value of sword gas damage.

Input
First enter a T, which indicates that there is a T group of data, followed by the T line:
Input four real a,b,c,d are less than or equal to 100

Output
The minimum damage value of the output sword gas is m, which retains the decimal point after one
(can use. 1lf)

Sample Input
2
0 0 3 4
4 0 0 3

Sample Output
5.0
5.0

A mathematics to find the distance between 2 points problem;
sqrt (x*x + y*y + m*m + n*n-2*m*x-2*n*y) is
sqrt ((x-m)(x-m) + (y-n)(y-n));
This is the distance from the point (x, Y) to (m,n) ~
In general, let's ask for a point P to P1 (A, B), p2 (b,c) the shortest distance of 2 points ~
It is obvious that the distance between P-points and the P1 and P2 is shortest.
That is, turn around and beg P1 to P2 distance.

ImportJava.util.Scanner;/** * * @author Chen Haoxiang * * 2016-5-16 * * Public  class Main{     Public Static void Main(string[] args) {Scanner SC =NewScanner (system.in);intT =sc.nextint (); while(t-->0){DoubleA = Sc.nextdouble ();Doubleb = sc.nextdouble ();Doublec = sc.nextdouble ();DoubleD = sc.nextdouble ();Doublem = math.sqrt ((a-c) * (a-c) + (b-d) * (b-d)); System.out.printf ("%.1f", m);        System.out.println (); }    }}

Hdoj/hdu 2547 No Sword no Me (distance between two points)

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.