【POJ 1905】 Expanding Rods
公式+二分
题意是一根棍 恰好夹在两面墙之间 在n温度下膨胀成(1+n*c)*l长度 问此时中的距原中点距离
膨胀后变成一段弧 也就是圆的一部分 原来的棍子就变成了圆的截线。。。这不是高中很常见的图么。。。
不会在电脑作图。。大家手画一下就知道了
这样做几条辅助线 从圆心做截线的垂线延长到弧 设棍子原长L 膨胀后(弧)长s 膨胀后中点与原中点距离h 半径r 半径与圆心到截线垂线的夹角θ 可以得到以下三个公式
sinθ = (L/2)/r
r^2 = (r-h)^2+(L/2)^2
s/(2*π*r) = (2*θ)/(2*π)
然后化简下 可得
θ = asin((L/2)/r)
r = ( L^2/(8*h) + h/2)
s = 2*θ*r = 2*asin((L/2)/r)*(L^2/(8*h) + h/2)
这么看肯定会乱 一定要自己画画写写 条例也会很清晰
然后二分中点距离即可 注意精度 还有g++的话要用%f输出!!被这个坑去好多wa
g++的话要用%f输出!!
g++的话要用%f输出!!
g++的话要用%f输出!!
重要的话说三遍 然后下界0 上界题目说 no rod expands by more than one half of its original length. 也就是s <= (3/2)*L 倒推得h <= L/2
代码如下:
#include <iostream> #include <cstdio> #include <cmath> #define esp 1e-5 using namespace std; int main() { double l,r,ll,rr,n,c,nl,h; while(~scanf("%lf %lf %lf",&ll,&n,&c)) { if(n < 0 && ll < 0 && c < 0) break; nl = (1+n*c)*ll; l = 0; r = ll/2; while(r - l > esp) { h = (l+r)/2; rr = (ll*ll/4+h*h)/(2*h); if(asin(ll/(2*rr))*rr < nl/2) l = h; else r = h; } printf("%.3f\n",h); } return 0; }