Expanding Rods(二分+几何)
2016-07-27 21:15
260 查看
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二分,应该也能写出来,但是太麻烦了。这个线性关系不好找。
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; else le=mid; } printf("%lf\n",r-r*cos(mid)); } return 0; }
相关文章推荐
- mysql提示command not found
- 新手学linux 之文件系统结构简介
- Populating Next Right Pointers in Each Node
- 判断链表是否有环
- CodeForces - 274A - k-Multiple Free Set
- 指针大小由什么决定
- 隐式Intent的一些用法
- aspx脱离源代码管理
- 标准库 vector 类型
- Java Web-1: 初级程序员目录和纲要
- 1020. 月饼 (25)
- POJ 3069 Saruman's Army
- heartbeat+drbd
- HDU 5762 Teacher Bo
- HDU 2242 强联通分量+树形DP
- My Html
- linux文件系统及目录结构
- 通过隧道连接内网的PostgreSQL以及跨域与部署方案
- 已有模板与tp框架的结合 (前台)
- Docker+Git+Jenkins+Cloud VM=CI+CD