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, &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