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 I got WA here?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator