Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

二分法WA的弟兄可以试试这个办法。。。。

Posted by hanjialong at 2008-08-06 20:15:52 on Problem 1905
我AC前也WA了7 8次了。。。。
大家可以试试这个方法:在xoy平面上一个很小矩形区域内的函数图像上做二分求根,因为范围太小所以精度容易出错。。。大家可以把图像做拉伸变换。。。。即在原式里另x=x'/B,y=y'/B。。。B为很大的一个正数。。。这样图像被拉大了。。。在新图上做二分求零点x'。。。然后除以B求x,这样精度会好一点。。。。

#include<iostream>
#include<cmath>
using namespace std;

long double l,n,c;

const long double e=1e-10;

const long double b=1e5;

long double co;

long double f1(long double sita)
{
	return b*co*sin(sita/b);
}

long double f2(long double sita)
{
	return sita;
}

long double getsita(long double l,long double r)
{
	if(r-l<=e) return (r+l)/2;
	long double mid=(l+r)/2;
	if(f1(mid)>f2(mid)) return getsita(mid,r);
	return getsita(l,mid);
}

long double ans()
{
	return l/2*tan(getsita(e,acos((long double)-1)*b/2)/2/b);
}

int main()
{
	while(scanf("%lf%lf%lf",&l,&n,&c)&&l>=-1*e)
	{
		co=1+n*c;
		printf("%.3lf\n",ans());
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator