| ||||||||||
| 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 | |||||||||
WHY TLE?谁能给点提示,代码见下./*
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator