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

ft,连那题都不肯说,就肯贴代码

Posted by 00448264 at 2005-04-25 18:39:13
In Reply To:这样肯定要超时,有没有好方法呢??求助 Posted by:cpp050300448067 at 2005-04-25 18:38:37
> #include <iostream.h>
> inline double dabs(double t)
> { if(t>=0) return t;
> 	else return -t;
> }
> void main()
> {
> 	double A;
> 	double d,n;
> 	int N,D;
> 	double exa;
> 	long L;
> 	cin >> A;
> 	int Ai = (int)A;
> 	cin >> L;
> 	exa = A - Ai;
> 	for( d=1;d <= L;d++)
> 		for(n=Ai * d ; n <= L;n++)
> 		  if(dabs(n/d - A)<exa)
> 			{N = n;
> 			 D = d;
> 			 exa = dabs(n/d - A);}
> 	cout << N << ' ' << D <<endl;
> }

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