标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 12773 | Accepted: 3291 |
Description
Input
Output
Sample Input
1000 100 0.0001 15000 10 0.00006 10 0 0.001 -1 -1 -1
Sample Output
61.329 225.020 0.000
题意:长度为L的铁片如图所示,升高温度C后会有一定程度的形变,长度变为NewL,呈圆弧状,求铁片中点偏离的高度
思路:数学题,解方程时构造函数二次求导求变化趋势,二分确定零点范围,怀念高考前刷数学试卷做导数题的时光。此题需注意精度以及数据为0的特判。
/** * Start at 12:53 * End at 13:08 * Problem: poj1905 * Author: __560 */ #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<math.h> using namespace std; const int maxn=1000100; const int INF=(1<<28); const double Pi=3.1415927; const double Exp=0.000000000001; double L,T,C; double NewL; double f(double x) { return L*x-NewL*sin(x); } double BinSearch(double left,double right) { while(fabs(left-right)>Exp){ double mid=(left+right)/2; if(f(mid)<0) left=mid; else if(mid>0) right=mid; } return left; } int main() { while(scanf("%lf%lf%lf",&L,&T,&C)!=EOF){ if(L==-1&&T==-1&&C==-1) return 0; if(L==0||T==0||C==0) puts("0.000"); else{ NewL=(1+C*T)*L; double x=BinSearch(Exp,Pi); double R=NewL/(2*x); double d=sqrt(R*R-L*L/4); printf("%.3f\n",R-d); } } }
标签:
原文地址:http://www.cnblogs.com/--560/p/4380596.html