hdu 5120 Intersection 圆环面积交

Intersection

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5120

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.

hdu 5120 Intersection 圆环面积交

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.

hdu 5120 Intersection 圆环面积交

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

HINT

题意

给你两个一样的圆环,问你这两个圆环相交的面积是多少

题解:

容斥定理就好了,剩下的都是套版

面积=大交大-大交小+小交小

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000006
#define mod 1001
#define eps 1e-9
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//*************************************************************************************
struct Circle{
double x,y;
double r;
}; double calArea(Circle c1, Circle c2)
{
double d;
double s,s1,s2,s3,angle1,angle2,temp; d=sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
if(d>=(c1.r+c2.r))//两圆相离
return ;
if((c1.r-c2.r)>=d)//两圆内含,c1大
return acos(-1.0)*c2.r*c2.r;
if((c2.r-c1.r)>=d)//两圆内含,c2大
return acos(-1.0)*c1.r*c1.r; angle1=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(*c1.r*d));
angle2=acos((c2.r*c2.r+d*d-c1.r*c1.r)/(*c2.r*d)); s1=angle1*c1.r*c1.r;s2=angle2*c2.r*c2.r;
s3=c1.r*d*sin(angle1);
s=s1+s2-s3; return s;
}
int main()
{
int t;
scanf("%d",&t);
for(int cas = ;cas <= t;cas++)
{
Circle a1,a2,b1,b2;
double R,r;
scanf("%lf%lf",&a1.r,&a2.r);
b1.r=a1.r;
b2.r=a2.r;
scanf("%lf%lf",&a1.x,&a1.y);
scanf("%lf%lf",&b1.x,&b1.y);
a2.x=a1.x;
a2.y=a1.y;
b2.x=b1.x;
b2.y=b1.y;
double ans = ;
ans += calArea(a1,b1);
ans -= calArea(a1,b2);
ans -= calArea(b1,a2);
ans += calArea(a2,b2);
printf("Case #%d: %.6lf\n",cas,ans);
}
}
上一篇:Python标准库:内置函数reversed(seq)


下一篇:bzoj1858[Scoi2010]序列操作 线段树