标签:div src c代码 pre style ble img using 几何
题目链接:https://vjudge.net/problem/POJ-1905
题意:有一根长len的木棍,加热了n度,长度会膨胀为len*(1+n*c),c为膨胀系数。现在把这根木棍夹在两堵墙之间,木棍会向上弯曲变成弧形,求弧形中点和原木棍中点的高度差。
思路:刚开始以为是几何题,几何肯定是能做的。然后发现题解是二分,第一次二分double类的变量,学到了。设所求答案为dis,通过dis可以勾骨出半径R,然后求出弧长L,再比较L与真实弧长len。显然dis和L满足二分的单调性,那么就可以做了。
AC代码:
#include<cstdio> #include<algorithm> #include<cmath> using namespace std; double len,len1,n,c; const double eps=1e-9; bool check(double d){ double R=d/2+len*len/8/d; return 2*R*acos((R-d)/R)<=len1; } int main(){ while(scanf("%lf%lf%lf",&len,&n,&c),len>=0){ if(len<eps||n<eps||c<eps){ printf("0.000\n"); continue; } len1=(1.0+n*c)*len; double l=1e-5,r=len/2,mid; while(l<=r){ mid=(l+r)/2; if(check(mid)) l=mid+(1e-5); else r=mid-(1e-5); } printf("%.3f\n",r); } return 0; }
标签:div src c代码 pre style ble img using 几何
原文地址:https://www.cnblogs.com/FrankChen831X/p/11408596.html