Hdu2547: no sword, no me

Source: Internet
Author: User
Problem description at the end of the Northern Song Dynasty, the traitor was in charge, the eunuchs were in power, the attackers were daily, and the Liao army committed another crime. Today, the war has been connected, and there have been a great number of talented people in different groups.
In the autumn of crisis, in an isolated place-a Jianghu on the mountain of the MCA said that the man who said <where did the hero come out> is studying jianfa for the fight against liaomiao thieves, at last, on the night of the thunder and lightning traffic, we accurately calculated the sword damage formula of the swing sword.

Define f (x, y, m, n) = SQRT (x * x + y * Y + M * m + n * n-2 * m * X-2 * n * y );
Hint: SQRT indicates the initiator, that is, SQRT (4) = 2; SQRT (16) = 4;

(X and Y are location variables, and m and n are attribute constants)
Sword damage = f (x, y, a, B) + f (x, y, C, D );
The Swordsman is extremely powerful and difficult to control. Now he wants to know the minimum damage value of the swordsman.

 

Input input a T, indicating that there is a T group of data, followed by the T line:
Input four real numbers, A, B, C, and D, all smaller than or equal to 100

Output: the minimum damage value of the swordsman (M). retain the last decimal point.
(. 1lf can be used)

Sample Input

20 0 3 44 0 0 3
 

Sample output

5.05.0
 

 

 

// I did this question in a very stupid way. After reading discuss, I realized that it was regular. But no matter how people do it, I 'd better paste my own code.

 

# Include <stdio. h> # include <math. h> double F (int x, int y, int M, int N) {return SQRT (x * x + y * Y + M * m + n * n-2 * m * X-2 * n * Y);} int main () {double A, B, C, D, t, x, y; double min, M; scanf ("% lf", & T); While (t --) {scanf ("% lf", & A, & B, & C, & D); min = 100000; For (x = 0; x <= 100; X ++) // use the X and Y loops to find the smallest sword. {for (y = 0; y <= 100; y ++) {M = f (x, y, a, B) + f (x, y, c, d); If (min> m) min = m ;}} printf ("%. 1lf \ n ", min);} return 0 ;}

 

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.