Expanding Rods二分

When a thin rod of length L is heated n degrees, it expands to a new length L' = (1 + n * C) * 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. That means you have to calculate h as in the picture.

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case contains three non-negative real numbers: the initial length of the rod in millimeters L, the temperature change in degrees n and the coefficient of heat expansion of the material C. Input data guarantee that no rod expands by more than one-half of its original length. All the numbers will be between 0 and 1000 and there can be at most 5 digits after the decimal point.

Output

For each case, print the case number and the displacement of the center of the rod in a single line. Errors less than 10-6 will be ignored.

Sample

InputcopyOutputcopy
3
1000 100 0.0001
150 10 0.00006
10 0 0.001
Case 1: 61.3289915
Case 2: 2.2502024857
Case 3: 0

题意:一根长为L的细棒经加热升高n度,其长度伸长为L'=(1+n*C)*L,现在将其两端固定在墙上,求图中的h。这道题实际上是讲了一个弓形,知道了他的弦长和弧长,也就是怎么求高的问题,其实求高,本道题的背景就是一个有原长为L的钢条,经过热胀冷缩以后变成了弓形的形状,他的温度变化是n度,然后热膨胀系数为C,膨胀后的钢条的弦长为L',计算公式为: L' = (1+n*C)*L

分析:此题用到很多数学知识。需要自己推导啊!首先说一下思路。用二分法枚举h高度的范围,从左端点0枚举至右端点R/2,右端点依题意可以确定。通过公式用枚举出的h计算得出该突出高度对应的膨胀后L'值,与题目中给出的L及伸长公式求出的L'相比较,若是求出的L'过大,则说明h取大了,求出的L'过小,说明h取小了。

注意:精度是将while循环的条件改为right-left>1e-6确定。

代码实现:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double low,high,mid;
	double l,n,s,c;
	double r;
	int num = 1;
	int t;
	scanf ("%d",&t);
	for(int i=0;i<t;i++)
	{
		scanf ("%lf %lf %lf",&l,&n,&c);
		printf ("Case %d: ",num++);
		s = (1.0+n*c)*l;
		low = 0;
		high = l / 2.0;
		while (high - low > 1e-8)  //注意精度 
		{
			mid = (high + low) / 2.0;//double所以除以2.0 
			r = (l*l + 4*mid*mid) / (8*mid);//根据勾股定理可以得到
			double t = asin(l/2/r);
			if (t * r * 2.0 < s)
				low = mid;
			else
				high = mid;
		}
		printf ("%.6f\n",low);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值