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

WA的不行了。。是精度问题还是方法错了?

Posted by Gilhirith at 2009-08-27 14:41:13 on Problem 2850
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int n,i,j,k,t;
double x,y,tx,ty,a,b,c,Dis1,Dis2,pos[2][15],q,E,F,h,Dis,A,B;

int main()
{
    scanf("%d",&t);
    for(k=1;k<=t;k++)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%lf",&pos[0][i]);
            pos[1][i]=1.0;
        }                               
        for(i=n-1;i>0;i--)
        {
            for(j=0;j<i;j++)
            {
                tx=(pos[0][j]+pos[0][j+1])/2.0;
                ty=(pos[1][j]+pos[1][j+1])/2.0;
                Dis1=pos[1][j]-pos[1][j+1];
                Dis2=pos[0][j]-pos[0][j+1];
                if(fabs(Dis1)<1e-8)
                {
                     x=tx;
                     y=sqrt(4.0-Dis2*Dis2/4.0)+pos[1][j];
                }
                else
                {                                               
                    h=sqrt(4.0-(Dis1*Dis1+Dis2*Dis2)/4.0);
                    Dis=sqrt(Dis1*Dis1+Dis2*Dis2);
                    A=asin(h/2.0);
                    B=atan(fabs(Dis1/Dis2));
                    y=pos[1][j]+2.0*sin(A-B);
                    x=pos[0][j]+2.0*cos(A-B);
                }
                pos[0][j]=x;
                pos[1][j]=y;
            }
        }
        printf("%d: %.4lf %.4lf\n",k,pos[0][0],pos[1][0]);
    }
    system("PAUSE");
    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