hdu5120(相交环面积)
来源:互联网 发布:学大数据看什么书 编辑:程序博客网 时间:2024/05/16 15:18
Intersection
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 41 Accepted Submission(s): 22
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.
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.
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
22 30 00 02 30 05 0
Sample Output
Case #1: 15.707963Case #2: 2.250778
题意:给你两个环,求相交部分面积。
分析:两环相交也就是图中黑色部分,然后用大圆相交面积 - 大小圆相交面积 +小圆相交面积。直接套模板。
代码:
#include<bits/stdc++.h>using namespace std;const double PI = acos(-1);// 圆的结构struct circle { double x; // 圆心横坐标 double y; // 圆心纵坐标 double r; // 半径};// 计算圆心距double dist(circle a, circle b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}// 计算两相交圆的面积double area(circle a, circle b) { if((dist(a, b)+min(a.r,b.r))<=max(a.r,b.r)) // 内含或重合 { if(a.r<b.r) return PI*a.r*a.r; else return PI*b.r*b.r; } else if(dist(a, b)>=(a.r+b.r)) // 相离或相切 return 0.0; else // 相交 { double length=dist(a, b); // 利用三角形余弦定理求圆心角 double d1=2*acos((a.r*a.r+length*length-b.r*b.r)/(2*a.r*length)); double d2=2*acos((b.r*b.r+length*length-a.r*a.r)/(2*b.r*length)); // 利用圆心角求得扇形面积再减去三角形面积后两部分相加就是相交部分面积 double area1=a.r*a.r*d1/2-a.r*a.r*sin(d1)/2; double area2=b.r*b.r*d2/2-b.r*b.r*sin(d2)/2; double area=area1+area2; return area; }}int main(){ int T; circle a, b, A, B; double r, R; scanf("%d", &T) ; while(T--) { scanf("%lf%lf%lf%lf%lf%lf", &r,&R,&a.x,&a.y,&b.x,&b.y); a.r = b.r = r; A.r = B.r = R; A.x = a.x; A.y = a.y; B.x = b.x; B.y = b.y; double sec = area(A, B) - area(A, b) - area(B, a) + area(a, b); static int t=1; printf("Case #%d: %.6f\n", t++, sec); } return 0;}
阅读全文
0 0
- hdu5120(相交环面积)
- HDU5120 Intersection 相交环面积 (2014北京现场赛)
- hdu5120 Intersection(平面几何+圆相交面积)
- HDU5120:Intersection(圆环相交)
- hdu5120 Intersection(求两个圆环相交的面积)
- hdu5120 两圆环相交 数学题
- HDU5120 Intersection 相交环总面积 (2014北京现场赛) 两圆香蕉模板
- HDU5120 Intersection(求两圆环相交)
- HDU5120 Intersection 【求圆的面积交】
- HDU5120(几何)
- hdu5120
- 两面相交面积面积
- 判断圆和矩形是否相交(非面积相交)
- 判断圆和矩形是否相交(非面积相交)
- HDOJ Intersection 5120【环相交面积】
- hdu 5120 Intersection(求相交环面积)
- [模板] 求两圆相交面积(模板)
- HDOJ 5120 Intersection(求两圆相交面积)
- python二进制文件转十进制
- angularjs数字转化为大写
- 前端学习站点:编程、框架、字体、插件
- 在Oracle存储过程中实现类Mybatis的动态sql
- 刷版子·总结(待补全......)
- hdu5120(相交环面积)
- [洛谷P3962]浮游大陆的68号岛
- 四,中断:中断程序(汇编和C语言)、idt、IDTR、8259A、8253以及发生中断时候的压栈细节和特权级保护
- 谷歌浏览器打开JSP页面依然输出源代码
- c++ assert() 使用方法
- HDU
- js查看Object对象的内容
- Xcode编译生成ipa文件(因为两种证书所以打两个ipa)
- 一个空循环程序