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 WA?!精度问题吗

Posted by garging at 2006-11-27 20:44:39 on Problem 1225
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stdlib.h>
#include<fstream>
#include<stdio.h>
#include<map>
using namespace std;

const double pi=3.14159253;

double dis(double x1,double y1,double x2,double y2)
{
	return sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}

int main()
{
	int i,n,k,nan,an[4];
	double a,b,c,A,B,C,afa;
	double x1,y1,x2,y2,x3,y3,d;
	double p1[3][3],p2[3],ans[4][3],dt;
	cin>>n;
	for(k=0;k<n;k++)
	{
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>d;
		afa=d/180*pi;
		a=dis(x2,y2,x3,y3);
		b=dis(x3,y3,x1,y1);
		c=dis(x1,y1,x2,y2);
		A=acos((b*b+c*c-a*a)/(2*b*c));
		B=acos((a*a+c*c-b*b)/(2*a*c));
		C=acos((a*a+b*b-c*c)/(2*a*b));
		nan=0;
		memset(an,0,sizeof(an));
		//0
		{
			p1[0][0]=sin(afa+C)*sin(afa+A);
			p1[0][1]=sin(afa)*sin(afa);
			p1[0][2]=-sin(afa)*sin(afa+C);
			p1[1][0]=-sin(afa)*sin(afa+A);
			p1[1][1]=sin(afa+A)*sin(afa+B);
			p1[1][2]=sin(afa)*sin(afa);
			p1[2][0]=sin(afa)*sin(afa);
			p1[2][1]=-sin(afa)*sin(afa+B);
			p1[2][2]=sin(afa+B)*sin(afa+C);
			p2[0]=c;
			p2[1]=a;
			p2[2]=b;
			dt=sin(afa)/(sin(afa+A)*sin(afa+B)*sin(afa+C)+sin(afa)*sin(afa)*sin(afa));
			for(i=0;i<3;i++)
			{
				ans[0][i]=p1[i][0]*p2[0]+p1[i][1]*p2[1]+p1[i][2]*p2[2];
				ans[0][i]*=dt;
			}
			//cout<<ans[0]<<' '<<a<<endl;
			//cout<<ans[1]<<' '<<b<<endl;
			//cout<<ans[2]<<' '<<c<<endl;
			if(ans[0][0]<a && ans[0][1]<b && ans[0][2]<c)
			{
				nan++;
				an[0]=1;
			}
		}
		//1
		{
			p1[0][0]=sin(afa+B)*sin(afa+B+C-A);
			p1[0][1]=sin(afa)*sin(afa+B-A);
			p1[0][2]=-sin(afa)*sin(afa+B+C-A);
			p1[1][0]=-sin(afa+B)*sin(afa+B-A);
			p1[1][1]=sin(afa+B)*sin(afa+B);
			p1[1][2]=sin(afa)*sin(afa+B-A);
			p1[2][0]=sin(afa+B-A)*sin(afa+B-A);
			p1[2][1]=-sin(afa+B)*sin(afa+B-A);
			p1[2][2]=sin(afa+B)*sin(afa+B+C-A);
			p2[0]=c*sin(afa);
			p2[1]=a*sin(afa+B-A);
			p2[2]=b*sin(afa+B-A);
			dt=1.0/(sin(afa+B)*sin(afa+B)*sin(afa+B+C-A)+sin(afa)*sin(afa+B-A)*sin(afa+B-A));
			for(i=0;i<3;i++)
			{
				ans[1][i]=p1[i][0]*p2[0]+p1[i][1]*p2[1]+p1[i][2]*p2[2];
				ans[1][i]*=dt;
			}
			//cout<<ans[0]<<' '<<a<<endl;
			//cout<<ans[1]<<' '<<b<<endl;
			//cout<<ans[2]<<' '<<c<<endl;
			if(ans[1][0]<a && ans[1][1]<b && ans[1][2]<c)
			{
				nan++;
				an[1]=1;
			}
		}
		//2
		{
			p1[0][0]=sin(A-afa)*sin(A-afa);
			p1[0][1]=sin(2*A-afa)*sin(A+C-afa);
			p1[0][2]=-sin(A-afa)*sin(A+C-afa);
			p1[1][0]=-sin(A-afa)*sin(A+C-afa);
			p1[1][1]=sin(A-afa)*sin(A+C-B-afa);
			p1[1][2]=sin(A+C-afa)*sin(A+C-afa);
			p1[2][0]=sin(2*A-afa)*sin(A+C-afa);
			p1[2][1]=-sin(2*A-afa)*sin(A+C-B-afa);
			p1[2][2]=sin(A-afa)*sin(A+C-B-afa);
			p2[0]=c*sin(A+C-afa);
			p2[1]=a*sin(A+C-afa);
			p2[2]=b*sin(2*A-afa);
			dt=1.0/(sin(A-afa)*sin(A-afa)*sin(A+C-B-afa)+sin(2*A-afa)*sin(A+C-afa)*sin(A+C-afa));
			for(i=0;i<3;i++)
			{
				ans[2][i]=p1[i][0]*p2[0]+p1[i][1]*p2[1]+p1[i][2]*p2[2];
				ans[2][i]*=dt;
			}
			//cout<<ans[0]<<' '<<a<<endl;
			//cout<<ans[1]<<' '<<b<<endl;
			//cout<<ans[2]<<' '<<c<<endl;
			if(ans[2][0]<a && ans[2][1]<b && ans[2][2]<c)
			{
				nan++;
				an[2]=1;
			}
		}
		//3
		{
			p1[0][0]=sin(A-afa)*sin(B-afa);
			p1[0][1]=sin(A+B-afa)*sin(B+C-afa);
			p1[0][2]=-sin(A-afa)*sin(B+C-afa);
			p1[1][0]=-sin(B-afa)*sin(C-afa);
			p1[1][1]=sin(B-afa)*sin(C-afa);
			p1[1][2]=sin(B+C-afa)*sin(C-afa);
			p1[2][0]=sin(A+B-afa)*sin(C-afa);
			p1[2][1]=-sin(A+B-afa)*sin(C-afa);
			p1[2][2]=sin(A-afa)*sin(C-afa);
			p2[0]=c*sin(B+C-afa);
			p2[1]=a*sin(A+C-afa);
			p2[2]=b*sin(A+B-afa);
			dt=1.0/(sin(A-afa)*sin(B-afa)*sin(C-afa)+sin(A+B-afa)*sin(B+C-afa)*sin(C-afa));
			for(i=0;i<3;i++)
			{
				ans[3][i]=p1[i][0]*p2[0]+p1[i][1]*p2[1]+p1[i][2]*p2[2];
				ans[3][i]*=dt;
			}
			//cout<<ans[0]<<' '<<a<<endl;
			//cout<<ans[1]<<' '<<b<<endl;
			//cout<<ans[2]<<' '<<c<<endl;
			if(ans[3][0]<a && ans[3][1]<b && ans[3][2]<c)
			{
				nan++;
				an[3]=1;
			}
		}
		cout<<nan<<endl;
		if(an[3]==1)
		{
			cout<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x2+ans[3][0]/a*(x3-x2)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y2+ans[3][0]/a*(y3-y2)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x3+ans[3][1]/b*(x1-x3)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y3+ans[3][1]/b*(y1-y3)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x1+ans[3][2]/c*(x2-x1)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y1+ans[3][2]/c*(y2-y1)<<endl;
			cout<<endl;
		}
		if(an[2]==1)
		{
			cout<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x3+ans[2][1]/b*(x1-x3)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y3+ans[2][1]/b*(y1-y3)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x2+ans[2][0]/a*(x3-x2)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y2+ans[2][0]/a*(y3-y2)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x1+ans[2][2]/c*(x2-x1)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y1+ans[2][2]/c*(y2-y1)<<endl;
			cout<<endl;
		}
		if(an[1]==1)
		{
			cout<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x2+ans[1][0]/a*(x3-x2)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y2+ans[1][0]/a*(y3-y2)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x1+ans[1][2]/c*(x2-x1)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y1+ans[1][2]/c*(y2-y1)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x3+ans[1][1]/b*(x1-x3)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y3+ans[1][1]/b*(y1-y3)<<endl;
			cout<<endl;
		}
		if(an[0]==1)
		{
			cout<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x1+ans[0][2]/c*(x2-x1)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y1+ans[0][2]/c*(y2-y1)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x2+ans[0][0]/a*(x3-x2)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y2+ans[0][0]/a*(y3-y2)<<endl;
			cout<<setiosflags(ios::fixed)<<setprecision(4)<<x3+ans[0][1]/b*(x1-x3)<<' '
				<<setiosflags(ios::fixed)<<setprecision(4)<<y3+ans[0][1]/b*(y1-y3)<<endl;
			cout<<endl;
		}
	}

	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