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

谢谢

Posted by Lucifer at 2005-08-14 21:41:38 on Problem 1183
In Reply To:请教。我得解法是O(n)的。但是不知道哪儿错了。 Posted by:Lucifer at 2005-08-13 18:32:48
> a=(bc-1)/(b+c)
> 令k=b+c
> 则b=k-c
> 所以a=((k-c)c-1)/k
> 化简为c*c+kc+(ak+1)=0;
> c=(-k+sqrt(k*k-4(a*k+1))/2
> 相应的b=(-k-sqrt(k*k-4(a*k+1))/2
> 因此我直接对k进行循环,依次k=k+1直到sqrt(k*k-4(a*k+1))为整数。。
> 但是不知道。为什么就WA了。。。。
> 
> #include <iostream.h>
> #include <math.h>
> int main()
> {
> 	unsigned long a,k;
> 	cin>>a;
> 	k=4*a;    //因为sqrt中的k*k-4(a*k+1)必须为正。
> 	long double t;
> 	t=sqrtl((unsigned long)(k*k-4*(a*k+1)));
> 	while (!(abs(t-(unsigned long)(t))<0.00000001))
> 	{
> 		k++;
> 		t=sqrtl((unsigned long)(k*k-4*(a*k+1)));
> 	}
> 	cout<<k<<endl;
> 	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