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 I got WA here?

Posted by noskill at 2005-04-21 10:33:06 on Problem 1079
It was Accepted in uva,but why WA here?

#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,i,j,m=0;
    double r,t,t1,t2,near;
    while(scanf("%d %d",&a,&b)==2)
    {
        if(m)printf("\n");
        r=(double)a/b;
        j=1;near=r;
          i=(int)(r);
          t1=(double)i;t2=(double)(i+1);
          if(fabs(t1-near)<fabs(t2-near))
            {printf("%d/%d\n",i,j);near=fabs(t1-r);}
          else 
            {printf("%d/%d\n",i+1,j);near=fabs(t2-r);}
        j++;
        while(j<=b)
        {
          i=(int)(r*j);
          t1=(double)i/j;t2=(double)(i+1)/j;
          if(fabs(t1-near)<fabs(t2-near)&&fabs(t1-r)<near)
            {printf("%d/%d\n",i,j);near=fabs(t1-r);}
          else if(fabs(t2-r)<near)
            {printf("%d/%d\n",i+1,j);near=fabs(t2-r);}
          j++;
        }    
        m++;
    }    
    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