二分--1043 - Triangle Partitioning

来源:互联网 发布:window10和mac对比 编辑:程序博客网 时间:2024/05/19 20:47

1043 - Triangle Partitioning
PDF (English)StatisticsForum
Time Limit: 0.5 second(s)Memory Limit: 32 MB

See the picture below.

You are given ABAC and BCDE 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

 


PROBLEM SETTER: JANE ALAM JAN



题目大意很明显,求AD 

思路:对AD二分  注意边和面积是平方的倍数关系(S=sqrt(p(p-a)(p-b)(p-c)) p=(a+b+c)/2 就能看出来了)

当然这题也可以找关系直接做出来






#include<stdio.h>#include<math.h>#define eps 1e-9#define min(a,b) ((a)<(b)?(a):(b))int main(){int t;double a,b,c,high,low,mid;scanf("%d",&t); double kk;//cout<<min(t,a);for(int i=1;i<=t;i++){scanf("%lf%lf%lf%lf",&a,&b,&c,&kk); high=a; low=0;while(high-low>eps){mid=(high+low)/2;if((mid/a)*(mid/a)>kk/(1+kk))  //找对关系式high=mid;else low=mid;}printf("Case %d: %.8lf\n",i,mid);}return 0;}


0 0