[UVA][數學] 11648 - Divide The Land
C |
Divide the Land Input: Standard Input Output: Standard Output |
Mr. Rahim Mia has some lands of trapezium shape. He wants to divide each of the lands between his two sons so that everyone gets equal area in every land. But as Mr. Rahim is not so good at mathematics, he is confused how to divide the lands equally. He decided to divide the land with a line parallel to the parallel lines of the trapezium. Yet he is getting problem to determine the points to draw the line. So he came to you. Please write a program for him that finds the distance of the points along the non-parallel lines of the trapezium to from the longer parallel line that will divide the land into two equal parts in terms of area. For example, consider the following figure, you have to find the lengths AE and BF so that ABFE and EFCD are equal in area and EF||AB given AB, BC, CD, DA.
Input
The first line of Input will be a number mentioning the number of lands Mr. Rahim has (at most 500). Each of the following numbers is description of Rahim’s land. Each description will consist of 4 positive integers mentioning AB, CD, AD and BC (less than 10000). You may assume that AB||CD and AB > CD. You may also assume that all of Rahim’s lands are trapezium shaped and has a positive area.
Output
For each of the lands you should output the number of the land and then the lengths AE and BF as two real numbers. Up to 1e-6 error in your output will be acceptable.
Sample Input Output for Sample Input
2 15 12 9 10 12 6 5 5 |
Land #1: 4.250767 4.723074 Land #2: 2.094306 2.094306
|
Problem setter: Md. Towhidul Islam, Special Thanks: Md. Arifuzzaman Arif
題目描述:
給一個梯行四邊長,平行其中兩邊將面積分成兩半。
求劃分時,交兩點 EF,AE BF 長 = ?
題目解法:
CD > AB,將 CD 拉兩條垂直線下來,利用高相當的方式,得到兩條畢氏定理相同。
藉此接出這個梯行四邊形的高,接著利用相似形,可以得到一個二元一次方程式,
求解即可。
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, d;
int cases = 0;
int testcase;
scanf("%d", &testcase);
while(testcase--) {
scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
double x = (d*d-c*c-a*a-b*b+2*a*b)/(2*b-2*a);
double y = a-b-x;
double h = sqrt(c*c-x*x);
double area = (b+a)*h/2;
double harea = area/2;
double ta, tb, tc;
ta = (x+y)/h, tb = 2*b, tc = -2*harea;
double sh = (-tb+sqrt(tb*tb-4*ta*tc))/2/ta;
printf("Land #%d: %lf %lf\n", ++cases, c*(1-sh/h), d*(1-sh/h));
}
return 0;
}