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
北京大学《ACM-ICPC竞赛训练》暑期课面向全球招生。容量有限,报名从速!

Re:精度够吗?

Posted by Magic347 at 2011-01-02 13:28:52 on Problem 2242
In Reply To:精度够吗? Posted by:zsc09_leaf at 2010-08-17 22:48:02
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

const double pi=3.141592653589793;
const double inf=0xfffffff;
const double eps=1e-10;

typedef struct Cord{

	double x , y ;

} cord ;

typedef struct Line{
	// depending on the existance of k  
	double k , b ;
	double x ;

} line ;

inline double get_dist( const cord& c1 , const cord& c2 )
{
	return sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));

}

inline cord get_mid( const cord& c1 , const cord& c2 )
{
	cord ret;
	ret.x=( c1.x+c2.x )/2.0 , ret.y=( c1.y+c2.y )/2.0;
	return ret;

}

inline double get_k( const cord& c1 , const cord& c2 )
{
	if( fabs(c1.x-c2.x)<eps ) return inf;
	return ( c1.y-c2.y )/( c1.x-c2.x );

}

inline double get_kk( const double& k )
{
	if( fabs(k-inf)<eps ){
		return 0;
	}
	if( fabs(k-0.0)<eps ){
		return inf;
	}
	return -1.0/k;

}

inline line get_line_cords( const cord& c1 , const cord& c2 )
{
	line ret;
	double k=get_k( c1 , c2 );
	if( fabs(k-inf)<eps ){	
		ret.k=inf , ret.b=inf , ret.x=c1.x;
		return ret;
	}
	ret.k=k , ret.b=c1.y-ret.k*c1.x , ret.x=inf;
	return ret;

}

inline line get_line_k( const cord& c , const double& k )
{
	line ret;
	if( fabs(k-inf)<eps ) {
		ret.k=inf , ret.b=inf , ret.x=c.x;
		return ret;
	}
	ret.b=c.y-k*c.x , ret.k=k , ret.x=inf;
	return ret;

}

inline cord get_intersector( const line& l1 , const line& l2 )
{
	cord ret;
	if( fabs(l1.k-inf)<eps ){
		ret.x=l1.x , ret.y=l2.k*l1.x+l2.b;
		return ret;
	}
	if( fabs(l2.k-inf)<eps ){
		ret.x=l2.x , ret.y=l1.k*l2.x+l1.b;
		return ret;
	}
	ret.x=( l1.b-l2.b )/( l2.k-l1.k );
	ret.y=( l2.k*l1.b-l1.k*l2.b )/( l2.k-l1.k );
	return ret;

}

int main( void )
{
	cord c1 , c2 , c3;
	cord mid12 , mid23 , o;
	line l12 , l23;
	double ans , k12 , k23 , r;
	while( cin>>c1.x>>c1.y>>c2.x>>c2.y>>c3.x>>c3.y ){
		
		mid12=get_mid( c1 , c2 ) , k12=get_kk( get_k( c1 , c2 ) ); 
		l12=get_line_k( mid12 , k12 );

		mid23=get_mid( c2 , c3 ) , k23=get_kk( get_k( c2 , c3 ) );
		l23=get_line_k( mid23 , k23 );
		
		o=get_intersector( l12 , l23 );
		r=get_dist( o , c3 );
		ans=2.0*pi*r;
		cout<<setiosflags(ios::fixed)<<setprecision(2)<<ans<<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