1043 - Triangle Partitioning(数学)
1043 - Triangle Partitioning
Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
See the picture below.
You are given AB, AC and BC. DE is parallel to BC. You are also given the area ratio between ADE and BDEC. You have to find the value of AD.
Input
Input starts with an integer T (≤ 25), denoting the number of test cases.
Each case begins with four real numbers denoting AB, AC, BC and the ratio of ADE and BDEC (ADE / BDEC). You can safely assume that the given triangle is a valid triangle with positive area.
Output
For each case of input you have to print the case number and AD. Errors less than 10-6 will be ignored.
Sample Input |
Output for Sample Input |
4 100 100 100 2 10 12 14 1 7 8 9 10 8.134 9.098 7.123 5.10 |
Case 1: 81.6496580 Case 2: 7.07106781 Case 3: 6.6742381247 Case 4: 7.437454786 |
题解:注意面积比是变长比的平方,另外p+1代表s/s2;s代表总面积,s2代表下面的四边形面积
代码:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<vector> #include<map> #include<algorithm> using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) #define SI(x) scanf("%d",&x) #define SL(x) scanf("%lld",&x) #define PI(x) printf("%d",x) #define PL(x) printf("%lld",x) #define P_ printf(" ") #define T_T while(T--) typedef long long LL; const int INF=0x3f3f3f3f; int main(){ int kase=0; double a,b,c,p; double d,area,ans; int T; SI(T); T_T{ scanf("%lf%lf%lf%lf",&a,&b,&c,&p); double k=p+1.0; p=sqrt(1.0-1/k); printf("Case %d: %lf\n",++kase,a*p); } return 0; }