Expanding Rods(二分+几何)

来源:互联网 发布:淘宝模特拍摄 下载 编辑:程序博客网 时间:2024/04/29 02:38
Expanding Rods
Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

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 single line. Errors less than 10-6 will be ignored.

Sample Input

3

1000 100 0.0001

150 10 0.00006

10 0 0.001

Sample Output

Case 1: 61.3289915

Case 2: 2.2502024857

Case 3: 0


题意:知道L,L2,求h

这里圆弧所对的圆心角的一半,最小0,最大二分之π。对角采用二分法,知道圆心角和弧长可以求出半径。用求出的半径和圆心角可以求出L的长,通过比较求出L的长和L的关系对角二分。求出圆心角在求出H。最开始直接对H二分,应该也能写出来,但是太麻烦了。这个线性关系不好找。

#include<cstdio>#include<math.h>#include<cstring>#include<stdlib.h>#include<algorithm>#define PI acos(-1)using namespace std;double l,n,c,r;int main(){int t,num;scanf("%d",&t);num=1;while(t--){scanf("%lf%lf%lf",&l,&n,&c);printf("Case %d: ",num++);double le=0,ri=PI/2.0,mid;double l2=(1+n*c)*l;while(ri-le>0.0000000001){mid=(le+ri)/2;r=(l/2)/sin(mid);if(r*2*mid>l2)ri=mid;elsele=mid;}printf("%lf\n",r-r*cos(mid));}return 0;}


0 0
原创粉丝点击