| ||||||||||
| 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 | |||||||||
50题,菜鸟贴代码留念~~~~~#include <iostream>
#include <math.h>
#define MAX 100000
#define EPS 1e-9
using namespace std;
int main()
{
double a;
int l;
while(cin >> a >> l)
{
int n = 1,d = 1,cn = n,cd = d;
double cmin = MAX;
while(n <= l && d <= l)
{
double cf = fabs(a - (double)n / d);
if(cf < EPS)
{
cd = d;
cn = n;
break;
}
if(cf < cmin)
{
cd = d;
cn = n;
cmin = cf;
}
if((double)n / d > a) d++;
else n ++;
}
printf("%d %d\n",cn,cd);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator