"Basic math Knowledge" UVa 11314-hardly hard

Source: Internet
Author: User

Problem hhardly Hard

You have been given the task of cutting out a quadrilateral slice of cake out of a larger, rectangular cake. You must find the slice with the smallest perimeter that satisfies the following constraints. If the cake is a size 10000-by-10000 units and is represented using the first quadrant of the Cartesian plane, then your Slice is quadrilateral ABCD (see figure). Points A and B are fixed and would be given to you. Also, A, B would lie on A negatively sloping line. Furthermore, points C and D must lie on the positive y-axis and positive x-axis respectively, but it's up to you deter Mine where these the points should be. A,b,c,d'll be distinct points.

Output of the minimum perimeter of your slice of cake.

Input

On the first line you'll be given n (1≤ n ≤100), the number of test cases. The following n lines each contain ax ay bx by (0 < ax, Ay, bx, by ≤10000.0), the Coordinat Es of Points A and B respectively.

Output

For each test case, the output of the perimeter accurate to 3 decimal places in its own line.

Test instructions: A rectangular cake cut out of a four-sided shape, requiring the smallest perimeter, where a, b two point coordinates are given, and the c,d point is required on the x, Y axis positive half axis.

Analysis: Symmetric point connection with X, Y axis. Proof very well, the shortest line between two points.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 #defineError 1e-86 using namespacestd;7 Const intMAXN =10010;8 9 Ten DoubleGet_len (DoubleX1,DoubleY1,DoubleX2,Doubley2) One { A     returnsqrt ((y2-y1) * (y2-y1) + (x2-x1) * (x2-x1)); - } - intMain () the { -  -     intT; -scanf"%d", &T); +      while(t--) -     { +         Doubleax, Ay, BX, by; Ascanf"%LF%LF%LF%LF", &ax, &ay, &AMP;BX, &by ); at         if(By <ay) {Swap (Ay, by); Swap (ax, BX);} -         DoubleCx=ax, Cy=-ay, DX=-BX, dy=by ; -printf"%.3lf\n", Get_len (CX, CY, DX, DY) +get_len (ax, Ay, BX, by)); -     } -     return 0; -}

"Basic math Knowledge" UVa 11314-hardly hard

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.