码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5120 Intersection

时间:2015-08-01 17:27:26      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

Intersection

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 967    Accepted Submission(s): 371


Problem Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.

技术分享

A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.

技术分享

Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.
 

Input
The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).

Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.
 

Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
 

Sample Input
2 2 3 0 0 0 0 2 3 0 0 5 0
 

Sample Output
Case #1: 15.707963 Case #2: 2.250778
 

Source

2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)  

几何计算题,,,有点麻烦

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a1,a2,b1,b2;
double d,p;
double area;
double fun(int a,int b)
{
    double sa,sb;
	d=sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));//圆心距 
	double rr=min(a,b);
	if(d<=abs(a-b))   //内含或者内切
 	  area=acos(-1.0)*rr*rr;
	else if(d>=a+b)//外切或不相交 
	      area=0.0;
	else{//相交求面积 
  	   p=(a+b+d)/2.0;//海伦公式里边的P 
	   sa=acos((a*a+d*d-b*b)/(2.0*a*d));//c^2=a^2+b^2-2*a*b*cos;求出圆心角 
	   sb=acos((b*b+d*d-a*a)/(2.0*b*d)); //同上      
  	   area=sa*a*a+sb*b*b-2*sqrt(p*(p-a)*(p-b)*(p-d));//两个扇形面积和就减去三角形面积,得相交部分面积 
	}
    return area;
}
int main()
{
	int t,k=0;
	int R,r;
	double s1,s2,s3,sum;
	while(scanf("%d",&t)!=EOF){
		while(t--){
		 k++;
		 scanf("%d%d%d%d%d%d",&R,&r,&a1,&b1,&a2,&b2);
		 s1=fun(R,R); s2=fun(r,r); s3=fun(R,r);//环的可以看作是两个圆,可以看出规律,,两个环相交的面积就等于
		 		//两个大圆相交的面积减去两次大圆和小圆相交的面积,再加上两个小圆相交的面积 
		 if(R>r)  sum=s1-2*s3+s2;
		 else sum=s2-2*s3+s1;
		 printf("Case #%d: %.6lf\n",k,sum);
		}
	}
	return 0;
} 


hdu 5120 Intersection

标签:

原文地址:http://blog.csdn.net/ling_du/article/details/47186947

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!