poj_1905 Expanding Rods(二分求单调函数)
2016-12-05 16:54
561 查看
Expanding Rods
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.InputThe input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Inputdata guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.OutputFor each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision.Sample Input
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 15684 | Accepted: 4160 |
![](http://poj.org/images/1905_1.jpg)
1000 100 0.0001 15000 10 0.00006 10 0 0.001 -1 -1 -1Sample Output
61.329 225.020 0.000
设θ为圆心角的一半,r为半径,h为要求的高度,则有
(1)sinθ = (L/2)/r;
(2)r^2 = (L/2)^2 + (r-h)^2;
(3)2*θ*r = L';
可得方程
r = (4*h^2+L^2)/(8*h);
L' = 2 * arcsin(L/(2*r)) * r;
之后就用二分法求单调函数,注意精度,太小WA,太大可能TLE。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <bitset>#include <queue>#include <set>#include <map>#include <string>#include <algorithm>#define FOP freopen("data.txt","r",stdin)#define FOP2 freopen("data1.txt","w",stdout)#define inf 0x3f3f3f3f#define maxn 1000010#define mod 1000000007#define PI acos(-1.0)#define LL long longusing namespace std;double n, C, L, L2;double f(double h){double r = (h*h*4 + L*L) / (h*8.0);return asin(L/(r*2.0)) * r * 2;}int main(){while(~scanf("%lf%lf%lf", &L, &n, &C) && (L != -1)){L2 = (1 + n * C) * L;double l = 0, r = L/2, m;while(r - l > 1e-4){m = (l+r)/2;if(f(m) < L2) l = m;else r = m;}printf("%.3f\n", m);}return 0;}
相关文章推荐
- 转移地址在寄存器的JMP指令
- glColor3f的次序对渲染的影响
- 第13周项目5-拓扑排序算法的验证
- Spark作为ETL工具与SequoiaDB的结合应用
- C++使用CriticalSection实现线程同步实例
- ASP.NET页面不被缓存
- laravel5.2 文件上传
- HTTP 1.1 版本新特性描述
- tomcat连接数线程数
- 非谓语动词
- TS流格式文件解析
- 深入理解Java内存模型(一)——基础
- Glide加载图片会出现淡绿色的背景
- oracle已知sys用户密码,进行密码更改
- 基于PCA(主成分分析)的人脸识别
- SSH(Sping,Struts2,Hibernate)和SSM(Sping,SpringMVC,MyBatis)的比较
- android通过nfs挂载linux共享的文件
- HTML代码规范
- iOS block分析
- 一张订单的生成(用面向对象思想设计订单类)