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 |
WA是精度问题么?#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n,i,j; double r[2][10],xc,yc,C,D,E,F,a,b,c,x,y,sq; while(scanf("%d",&n)==1&&n) { for(i=0;i<n;i++) { scanf("%lf",&r[0][i]); r[1][i]=1.0; } sort(r[0],r[0]+n); for(j=n-1;j>0;j--) for(i=0;i<j;i++) { xc=(r[0][i]+r[0][i+1])/2.0; yc=(r[1][i]+r[1][i+1])/2.0; C=r[1][i]-r[1][i+1]; D=r[0][i]-r[0][i+1]; if(fabs(C)<0.0000000000001) { x=xc; a=1.0; b=-2.0*r[1][i]; c=r[1][i]*r[1][i]+(x-r[0][i])*(x-r[0][i])-4.0; sq=b*b-4.0*a*c; y=(sqrt(sq)-b)/(2.0*a); } else { E=-D/C; F=yc+D*xc/C; a=1.0+E*E; b=-2.0*r[0][i]+2.0*E*(F-r[1][i]); c=(F-r[1][i])*(F-r[1][i])+r[0][i]*r[0][i]-4.0; sq=b*b-4.0*a*c; x=(sqrt(sq)-b)/(2.0*a); y=E*x+F; } r[0][i]=x; r[1][i]=y; } printf("%.4lf %.4lf\n",r[0][0],r[1][0]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator