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 majia5 at 2008-07-30 18:39:29 on Problem 2546 and last updated at 2008-07-30 18:40:31
#include <iostream>
#include <math.h>
using namespace std;
const double pi = 3.141592654;
struct circle
{
	double x,y;
	double r,intersection_area,intersection_radio;
	bool check_intersection(const circle&a) const
		{
			if((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y)>=(r+a.r)*(r+a.r))
				return false;
			return true;
		}
	bool check_is_inside(const circle&a)
		{
			return sqrt((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y))+a.r<=r;
		}
	void get_intersection_radio(const circle&a) 
		{
			double dis=(x-a.x)*(x-a.x)+(y-a.y)*(y-a.y);
			intersection_radio= 2*(acos(0.5*(r*r+dis-a.r*a.r)/(r*sqrt(dis))));
		}
	void get_intersection_area()
		{
			intersection_area=intersection_radio*r*r*0.5-r*r*sin(intersection_radio)*0.5;
		}
}a,b;
int main()
{
	double res;
	while(cin>>a.x>>a.y>>a.r>>b.x>>b.y>>b.r)
		{
			if(!a.check_intersection(b))
				cout<<"0.000"<<endl;
			else
				{
					if(a.check_is_inside(b))
						{
							printf("%.3lf\n",pi*a.r*a.r);
							continue;
						}
					if(b.check_is_inside(a))
						{
							printf("%.3lf\n",pi*b.r*b.r);
							continue;
						}
					a.get_intersection_radio(b);
					a.get_intersection_area();
					res=a.intersection_area;
					b.get_intersection_radio(a);
					b.get_intersection_area();
					res+=b.intersection_area;
					printf("%.3lf\n",res);
				}
		}
	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