hdu 5120 (求两圆相交的面积

  题意:告诉你两个圆环,求圆环相交的面积。

/*  gyt
       Live up to every day            */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 605;
const ll maxm = 1e7;
const ll mod = 1e9 + 7;
const int INF = 0x3f3f3f;
const ll inf = 1e15 + 5;
const db eps = 1e-9;
int a1, b1, a2, b2;

db getArea(int a, int b) {
    db sa, sb;
    db d=sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
    db rr=min(a, b);
    db area=0;
    if (d<=abs(a-b))  area=acos(-1.0)*rr*rr;  //内含或者内切
    else if (d>=a+b)  area=0.0;  //外切或不相交
    else {  //相交求面积
        db p=(a+b+d)/2.0;  //海伦公式里边的P
        db sa=acos((a*a+d*d-b*b)/(2.0*a*d));  //c^2=a^2+b^2-2*a*b*cos;求出圆心角
        db 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;
}
void solve() {
    static int ca=1;
    int R, r;
    scanf("%d%d%d%d%d%d", &R, &r, &a1, &b1, &a2, &b2);
    db s1=getArea(R, R), s2=getArea(r, r), s3=getArea(R, r);
    db sum=0;
    if (R>r)  sum=s1-2*s3+s2;
    else    sum=s2-2*s3+s1;
    printf("Case #%d: %.6f\n", ca++, sum);
}
int main() {
    int t = 1, cas = 1;
   // freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
    scanf("%d", &t);
    while(t--) {
        solve();
    }
    return 0;
}
时间: 2024-10-10 00:18:10

hdu 5120 (求两圆相交的面积的相关文章

hdu 5120 (求两圆相交的面积的公式)

S = A大B大 - A大B小 - A小B大 + A小B小.(A表示A环,大表示大圆,B同).然后直接套模板,,,, 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <cmath> 5 using namespace std; 6 7 const double eps = 1e-8; 8 const double PI = acos(-1.0); 9 1

POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

题目链接: POJ:http://poj.org/problem?id=2546 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three di

求两圆相交部分面积(C++)

已知两圆圆心坐标和半径,求相交部分面积: 1 #include <iostream> 2 using namespace std; 3 #include<cmath> 4 #include<stdio.h> 5 #define PI 3.141593 6 struct point//点 7 { 8 double x,y; 9 }; 10 struct circle//圆 11 { 12 point center; 13 double r; 14 }; 15 float

求两圆相交的面积

走自己的路,你会发现,在走的过程中你会收获很多 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <limits.h> #include <ctype.h> #include <string.h> #include <string> #include <algorithm> #include <iostream>

hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径. 对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 #define maxn 50 int n; struct point{

求两圆相交面积模板

#define PI 3.141592654 #define eps 1e-8 double getdis(int x1,int y1,int x2,int y2){ return sqrt((double)(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } double getarea(int x1,int y1,double r1,int x2,int y2,double r2){ double d=getdis(x1,y1,x2,y2); if(r1+r2<d+eps)

HDU 1798 两圆相交面积

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1755    Accepted Submission(s): 535 Problem Description There are two circles in the plane (shown in the below picture), there is

poj 2546 Circular Area (两圆相交面积)

链接:poj 2546 题意:已知两圆的圆心和半径,求两圆相交部分的面积 分析:两圆的位置关系有三种:相离,相交,内含 相离时:相交面积为0 相交时,大扇形面积+小扇形面积-四边形面积 内含时,相交面积为小圆面积 #include<stdio.h> #include<math.h> #define PI acos(-1.0) typedef struct stu { double x,y; }point; double Distance(point a,point b) { ret

hdu 3264 Open-air shopping malls(求圆相交的面积,二分)

Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2256    Accepted Submission(s): 837 Problem Description The city of M is a famous shopping city and its open-air shopping