站军姿-两圆并集

站军姿

背景: 
站军姿是一件非常痛苦的事情,特别当教官在附近游荡时。 
题目描述: 
有两个教官,每个教官又一个位置坐标和一个视线范围,该教官能够观察到以该位置为圆心,给定半径的一个圆,你需要求出有多大面积的地方在两个教官的视线范围内。 
由于教官四处游荡,因此你需要实现多组数据。 
输入描述: 
第一行一个数T表示数据组数。 
接下来T行每行六个实数,分别为x1,y1,r1,x2,y2,r2,代表两个教官的各项参数。 
输出描述: 
每组数据输出一行表示答案,答案保留三位小数。 
样例输入: 

3 3 1 3 3 0.5 
样例输出: 
3.142 
数据范围: 
对于10%的数据,两圆相离 
对于10%的数据,两圆为包含关系 
对于另外40%的数据,满足T=1且0≤|x|,|y|,r≤5 
对于100%的数据,T≤10,0≤|x|,|y|,r≤le5

思路:

  分为 相离,相交,内含。三种情况,一一判定即可。

  相交的话麻烦一点:

  用扇形的面积减去三角形面积,就是弓形面积,减去弓形面积即可。

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define N 1000009
double x11,y11,x2,y2,r1,r2;
double L,ans,pi=3.1415926;
int main()
{
    freopen("standing.in","r",stdin);
    freopen("standing.ans","w",stdout);
    int T;
    scanf("%d",&T);
while(T--)
{

    cin>>x11>>y11>>r1>>x2>>y2>>r2;
    L=(x11-x2)*(x11-x2)+(y11-y2)*(y11-y2);
    if(L>=(r1+r2)*(r1+r2))
    {
        ans=(double)(pi*r1*r1+pi*r2*r2);
        printf("%.3lf",ans);
    }else
    if(L<=(r1-r2)*(r1-r2))
    {
        ans=(double)(pi*max(r1,r2)*max(r1,r2));
        printf("%.3lf",ans);
    }else
    {
        double all=(pi*r1*r1+pi*r2*r2);
        double a=acos((L+r1*r1-r2*r2)/(2*sqrt(L)*r1));
        double s=r1*r1*a- r1*r1*sin(a)*cos(a);
        all-=s;

         a=acos((L+r2*r2-r1*r1)/(2*sqrt(L)*r2));
        s=r2*r2*a- r2*r2*sin(a)*cos(a);
        all-=s;
        printf("%.3lf",all);
    }

}
    return 0;
}

样例:

2

输入:  

2
1 0 2
1 1 2

0 0 1
3 3 1

输出:

  16.524

  6.283

时间: 2024-08-17 10:17:52

站军姿-两圆并集的相关文章

POJ 2546 &amp; ZOJ 1597 Circular Area 两圆的面积交

Circular Area Time Limit: 2 Seconds      Memory Limit: 65536 KB Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point. Input In the single line of in

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

poj 2546(两圆公共面积)

Circular Area Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5682   Accepted: 2225 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after

求两圆相交部分面积(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

[读书笔记]站在两个世界的边缘

"真正牛逼的,不是那些可以随口拿来夸耀的事迹,而是那些在困境中依然保持微笑的凡人." "幸福就是一觉醒来,窗外的阳光依然灿烂." "也许我们无法明白'活着'的意义,但是我们已经为'活着'付出了太多代价:也许我们无法实现自己的梦想,但是我们已经为梦想流下了太多泪水.我们能做的,仅仅是在这条路上走得更远,绝不能回头.天堂未必在前方,但地狱一定在身后." "生命之残酷,在于其短暂:生命之可贵,亦在于其短暂." "这些遗留下

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{

UVa 10674 (求两圆公切线) Tangents

题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果高中的那点老底还在的话,代码还是很好理解的. 1 //#define LOCAL 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #incl

iOS之两圆之间标准圆的随机生成

相信很多社交产品中,肯定会存在寻找附近人或者附近商家的需求,类似下图,在大圆和小圆之间(橘色区域)生成一系列的随机圆,并且所有随机圆之间也不能有交集,我暂且称这种圆为标准圆. 关于这样的需要以前在做项目中有同事做过,虽然可以实现了上面的效果图,但是坐标及半径都是写死,从写死的数据随机取值,看上去是满足了,但是对于用户来说多次使用该功能时,肯定有一定的视觉疲倦,且写死的一些数据真的不好写,如果大圆或者小圆半径变化了,或者需要更多的标准圆,那怎么办呢?一脸懵逼?? 思路一: 对于这个需求,我一开始也

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