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 |
(1)这种题新加的数据最好用避开浮点的方式去验证一下。(2)vc和gcc默认的fpu precision是不同的,vc是53为,gcc是64位,这一点点差别足以导致waIn Reply To:Why I got WA here? Posted by:noskill at 2005-04-21 10:33:06 我2018最早的ac程序就没有通过我自己做的数据,就是因为浮点误差导致的 > 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