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

WHY TLE?谁能给点提示,代码见下.

Posted by VitaminC at 2006-11-23 12:56:29 on Problem 3039
/*
	Problem ID: 3039
	User ID: VitaminC
	Time: 2006-11-23
*/
#include<stdio.h>
#include<math.h>

int main()
{
	double n, d;
	double result, min_dif;
	int min_n, min_d;
	while(2 == scanf("%lf%lf", &n, &d), n>=1 && n<=32767 && d>=1 && d<=32767)
	{
		result=n/d;
		min_dif=1.0;
		int c1, c2;
		double dif1, dif2;
		for(int i=1; i<=32767; i++)
		{
			if((int)i%(int)d==0)
				continue;
			c1=(int)(i*result);
			c2=c1+1;
			dif1=fabs(c1/(double)i-result);
			dif2=fabs(c2/(double)i-result);
			if(dif1<min_dif)
			{
				min_dif=dif1;
				min_n=c1;
				min_d=i;
			}
			if(dif2<min_dif)
			{
				min_dif=dif1;
				min_n=c2;
				min_d=i;
			}
		}
		printf("%d %d\n", min_n, min_d);
	}
	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