POJ 1905 Expanding Rods(实数二分)
作者:互联网
题目链接:点击这里
一看就是实数二分的题
正常情况下我们需要讨论加热后的长度与h的单调性,函数过于复杂,但根据常识可判断出:h越大,加热后的长度越长,因此,考虑二分法。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 1010;
int a[maxn];
double L, n, c;
int main()
{
while(~scanf("%lf%lf%lf", &L, &n, &c))
{
if(L<0&&n<0&&c<0) break;
double left = 0, right = L/2;
while(right-left > eps)
{
double mid = left+(right-left)/2;
double R = (4*mid*mid + L*L)/(8*mid);
double theta = asin(L/(2*R));
if(2*theta*R < (1+n*c)*L) left = mid;
else right = mid;
}
printf("%.3f\n", left);
}
return 0;
}
菜是原罪QAQ
发布了690 篇原创文章 · 获赞 103 · 访问量 11万+
关注
标签:const,int,Expanding,mid,POJ,double,Rods,include,left 来源: https://blog.csdn.net/qq_42815188/article/details/104074196