Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用牛顿迭代为什么老是WA?#include <cstdio> #include <cmath> const double ep = 1e-12; const double pi = 3.1415926535897932324626; int main() { double l,l1,n,c,r,h; double x0,x1,k; scanf("%lf %lf %lf",&l,&n,&c); while(l >= 0 || n >= 0 || c >= 0) { l1 = l * (1.0 + n * c); k = l / l1; x0 = pi * 0.125; x1 = x0 - (sin(x0) - k * x0) / (cos(x0) - k); while(fabs(sin(x1) - k * x1) > ep && fabs(x1 - x0) > ep) { x0 = x1; x1 = x0 - (sin(x0) - k * x0) / (cos(x0) - k); } r = l1/2/x1; h = r * (1 - cos(x1)); printf("%0.3lf\n",h); scanf("%lf %lf %lf",&l,&n,&c); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator