POJ-1905

题目
When a thin rod of length L is heated n degrees, it expands to a new length L’=(1+nC)L, where C is the coefficient of heat expansion.
When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment.
Your task is to compute the distance by which the center of the rod is displaced.
题目大意
红线为L’,蓝线为L,求h
解题思路
算!
设半径为R
θ=arcsin(L/2R)
L’=2θ/(2π) * 2πR=2Rθ
L=2sqrt((R * R) -(R-h) * (R-h))
整理上式子得
L’=2Rarcsin(L/2R) ①
R=(L * L+4h
h)/(8h) ②
将②带①
s= L’=(4
hh+LL)/4.0/hasin(4hL/(4h*+L*L))
s对h求导得到s’在h>=0时是单调增加的
所以可以用二分法求h
代码实现

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
const double esp=1e-5;
int main()
{
	while (true)
	{
		double L,n,c,ans=0,s;
		cin>>L>>n>>c;
		if (L<0) break;
		s=(1+n*c)*L;
        double l=0.0,r=L;
		while (l+esp<=r)
		{
			double mid=(l+r)/2;
			double R=(4*mid*mid+L*L)/(8*mid);
			double a=2*R*asin(L/(2*R));
			if (a<=s) l=mid;
		    else r=mid;
		    ans=mid;
		}
		printf("%.3f\n",ans);
	}
} 
发布了13 篇原创文章 · 获赞 0 · 访问量 172

猜你喜欢

转载自blog.csdn.net/weixin_45723759/article/details/103955204
今日推荐