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 |
牛顿迭代吧,二次收敛,选择一个好的初值可以收敛得很快In Reply To:不是WA就是tle,有什么好方法吗?(附程序) Posted by:TN at 2005-01-24 13:02:36 > #include<cstring> > #include<cstdio> > #include<cmath> > using namespace std; > double l,n,c,l1,hi,lo,pi,mid,f; > int main(void){ > > while(true){ > scanf("%lf %lf %lf",&l,&n,&c); > if(l<0 || n<0 ||c<0)break; > l1=l+n*c*l; > pi=3.1415926;mid=0; > hi=pi/2;lo=0;mid=(hi+lo)/2; > f=mid*l-sin(mid)*l1; > while (abs(f)>1e-12) > { > if (f>0) hi=mid; else lo=mid; > mid=(hi+lo)/2; > f=mid*l-sin(mid)*l1; > } > printf("%.3lf\n",l1/mid/2*(1-cos(mid))); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator