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

50题,菜鸟贴代码留念~~~~~

Posted by yingxiang720 at 2011-03-22 10:54:50 on Problem 1650
#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:
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