hdu 5120 - Intersection(解题报告)

Intersection

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)

Total Submission(s): 1036    Accepted Submission(s): 407

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

题意:

求两圆环相交的面积。

参考代码:

#include<stdio.h>
#include<math.h>
#define PI acos(-1.0)
double sum(double a1,double b1,double r1,double a2,double b2,double r2)
{
    double A1,A2,s1,s2,s,d;
        d=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1));
        if(d>=r1+r2)
            return 0.000;
        else if(d<=fabs(r1-r2))
        {
            if(r1>r2)
                return PI*r2*r2;
            else
                return PI*r1*r1;
        }
        else{  

            A1=2*acos((d*d+r1*r1-r2*r2)/(2*d*r1));
            A2=2*acos((d*d+r2*r2-r1*r1)/(2*d*r2));
            s1=0.5*r1*r1*sin(A1)+0.5*r2*r2*sin(A2);
            s2=A1/2*r1*r1+A2/2*r2*r2;
            s=s2-s1;
            return s;
        }
}
int main()
{
	int t;
	scanf("%d",&t);
	for(int q=1;q<=t;q++)
	{
		double r1,r2,a1,a2,b1,b2;
		scanf("%lf%lf%lf%lf%lf%lf",&r1,&r2,&a1,&b1,&a2,&b2);
		printf("Case #%d: ",q);
		printf("%.6lf\n",sum(a1,b1,r2,a2,b2,r2)-2*sum(a1,b1,r2,a2,b2,r1)+sum(a1,b1,r1,a2,b2,r1));
	}
	return 0;
}

版权声明:本文为博主原创文章,随便转载。

时间: 2024-12-19 12:18:24

hdu 5120 - Intersection(解题报告)的相关文章

hdu 1541 Stars 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有比它低层(或者同层)的或者在它左手边的星星数决定.计算出每个等级(0 ~ n-1)的星星各有多少颗. 我只能说,题目换了一下就不会变通了,泪~~~~ 星星的分布是不是很像树状数组呢~~~没错,就是树状数组题来滴! 按照题目输入,当前星星与后面的星星没有关系.所以只要把 x 之前的横坐标加起来就可以了

Valentine&#39;s Day Round 1001.Ferries Wheel(hdu 5174)解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1]<A[i]<A[i+1](1<i<K).现在要求的是,有多少人满足,(他坐的缆车的值 + 他左边缆车的值) % INT_MAX == 他右边缆车的值. 首先好感谢出题者的样例三,否则真的会坑下不少人.即同一部缆车可以坐多个人.由于缆车的值是唯一的,所以可以通过排序先排出缆车的位置.求出

hdu 1963 Investment 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 题目意思:有 本金 money,还有一些股票的种类,第 i 种股票买入需要 value[i] 这么多钱,相应会有一定的利息interest[i],问经过若干年 year 后,每年都以最优的方案投资,总的资金有多少? 完全背包题,不过要看清楚 这句话:The value of a bond is always a multiple of $1 000,否则TLE了 1 #include <ios

hdu 超级楼梯 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 哦--对了,这些题读者可以直接忽略,我只是想练习一下自己薄弱的地方...... 题目意思我就不说了...自从昨晚问完乌冬兄一条DP题之后,“一体就知道系DP啦,而且仲好简单噶DP...”.就深感自己是如此地弱......可能有一段相当漫长的时间不会再找他了,毕竟一个喳喳对着一个区域赛银牌的人,自尊心作祟,而且,很大压力!我发现我好多不会......他好像以为我什么都会...... 这条题以前做

HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环由一个大圆里面套一个小圆,中间部分就是圆环,两圆环相交面积 = 大圆相交的面积 - 2*大圆与小圆相交的面积 + 小圆与小圆相交的面积. 也就是说,这题就可以化为求两个圆的相交的面积了.可以利用两个圆的方程,求出圆的交点所在的直线,然后求出圆心到这条直线的距离,就可以求出两个圆对应的扇形的圆心角是多

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

hdu 5120 Intersection

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 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 bel

BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: a,b.表示 process b 要在 process a 之前完成.问经过 m 种关系之后,有没有可能完成所有的 process. 可以利用拓扑排序的思想做.遍历所有 process,处理所有入度为 0 的点,然后把与该点关联的点,即度数都减一.这样处理完之后,每个点的度数应该都是-1,否则就代

Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b2, ...,  bt.需要满足两个条件(1)b1≤b2≤…≤bt   (2)b2−b1≤b3−b2≤?≤bt−bt−1.求出最大的 t 为多少. 遗留大半年的题目呀呀呀呀~~~~!!!首先非常感谢乌冬子大半年前的指点迷津,呕心沥血想了大半天举出个反例,以便指出我算法的错误.为了纪念这个伟大的人物(