24h購物| | PChome| 登入
2012-03-25 13:10:46| 人氣866| 回應0 | 上一篇 | 下一篇

[UVA][Math] 11314 - Hardly Hard

推薦 0 收藏 0 轉貼0 訂閱站台

Problem H

HARDLY 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 of 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 will be given to you. Also, A,B will 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 is up to you to determine where these two points should be. A,B,C,D will be distinct points.

Output the minimum perimeter of your slice of cake.

Input

On the first line you will 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 coordinates of points A and B respectively.

Output

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

Sample Input

1
3.0 1.0 1.0 2.0

Output for the Sample Input

7.236

做法 : 高中數學,
A點對X軸找出對稱點A',B點對Y軸找出對稱點B'
AB + A'B' 即為最小值

#include <stdio.h>
#include <math.h>
int main() {
int n;
double ax, ay, bx, by;
double cx, cy, dx, dy;
scanf("%d", &n);
while(n--) {
scanf("%lf %lf %lf %lf", &ax, &ay, &bx, &by);
cx = -bx, cy = by;
dx = ax, dy = -ay;
printf("%.3lf\n", sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))+sqrt((cx-dx)*(cx-dx)+(cy-dy)*(cy-dy)));
}
return 0;
}
 

台長: Morris
人氣(866) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][CutPoint] 315 - Network
此分類上一篇:[UVA][Math] 11038 - How Many O's?

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文