HDU 4386 Quadrilateral(數學啊)
阿新 • • 發佈:2017-05-24
algo data 長度 please sca wan post play dsm
Input The first line contains an integer N (1 <= N <= 10000) which indicates the number of test cases. The next N lines contain 4 integers a, b, c, d, indicating the length of the crabsticks.(1 <= a, b, c, d <= 1000)
Output For each test case, please output a line “Case X: Y”. X indicating the number of test cases, and Y indicating the area of the quadrilateral Jack want to make. Accurate to 6 digits after the decimal point. If there is no such quadrilateral, print “-1” instead.
Sample Input
Sample Output
Author WHU
Source 2012 Multi-University Training Contest 9
題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=4386
Input The first line contains an integer N (1 <= N <= 10000) which indicates the number of test cases. The next N lines contain 4 integers a, b, c, d, indicating the length of the crabsticks.(1 <= a, b, c, d <= 1000)
Output For each test case, please output a line “Case X: Y”. X indicating the number of test cases, and Y indicating the area of the quadrilateral Jack want to make. Accurate to 6 digits after the decimal point. If there is no such quadrilateral, print “-1” instead.
Sample Input
2 1 1 1 1 1 2 3 4
Sample Output
Case 1: 1.000000 Case 2: 4.898979
Author WHU
Source 2012 Multi-University Training Contest 9
題意:
給出四條邊的長度,求是否能形成四邊形。假設能形成求最大面積。
PS:
四邊形最大面積:
L = (A+B+C+D)/2;
AREA = sqrt((L-A) * (L-B)*(L-C)*(L-D));
代碼例如以下:
#include <cstdio> #include <cmath> #include <algorithm> using namespace std; int main() { int t; int cas = 0; scanf("%d",&t); while(t--) { int a[4]; for(int i = 0; i < 4; i++) { scanf("%d",&a[i]); } sort(a,a+4); int sum = a[0]+a[1]+a[2]; if(sum <= a[3]) { printf("Case %d: -1\n",++cas); continue; } double p = (a[0]+a[1]+a[2]+a[3])/2.0; double area = sqrt((p-a[0])*(p-a[1])*(p-a[2])*(p-a[3])); printf("Case %d: %.6lf\n",++cas,area); } return 0; }
HDU 4386 Quadrilateral(數學啊)