标签:
题目链接:http://lightoj.com/volume_showproblem.php?problem=1043
题意:一个三角形ABC,DE//BC,已知三角形ADE和四边形BDEC的面积的比,求AD的长度。
解法:二分AD边即可
代码:
#include <stdio.h>
#include <ctime>
#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
using namespace std;
int main()
{
int t; int cases = 1;
double a, b, c, ratio;
scanf("%d",&t);
while (t--)
{
cin >> a >> b >> c >> ratio;
double s = a*b;
double ans;
ratio = ratio / (ratio + 1.0);
double left = 0, right = a;
double mid;
while (left + 0.000000001<= right)
{
mid = (left + right) / 2.0;
ans = mid * b * (mid / a);
ans /= s;
if (ans >= ratio) right = mid;
else left = mid;
}
printf("Case %d: ", cases++);
printf("%.9lf\n", right);
}
return 0;
}
版权声明:转载请注明出处。
Lightoj 1043 - Triangle Partitioning【二分】
标签:
原文地址:http://blog.csdn.net/u014427196/article/details/47027441