博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Intersection(计算几何)
阅读量:6038 次
发布时间:2019-06-20

本文共 2741 字,大约阅读时间需要 9 分钟。

Intersection

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

Total Submission(s): 3018    Accepted Submission(s): 1135

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
 

 

Source

 

 

//题意:问两个同样大的圆环相交的面积是多大

画图后,可以发现,用容斥定理很简单,area = 两个大圆的相交面积 - 2 * 大圆和小圆相交面积 + 两个小圆相交面积

求面积要用余弦定理,然后就简单了

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 using namespace std;13 #define LL long long14 #define PI acos(-1.0)15 #define lowbit(x) (x&(-x))16 #define INF 0x7f7f7f7f // 21 E17 #define MEM 0x7f // memset 都变为 INF18 #define MOD 4999 // 模19 #define eps 1e-9 // 精度20 #define MX 1000005 // 数据范围21 22 int read() { //输入外挂23 int res = 0, flag = 0;24 char ch;25 if((ch = getchar()) == '-') flag = 1;26 else if(ch >= '0' && ch <= '9') res = ch - '0';27 while((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + (ch - '0');28 return flag ? -res : res;29 }30 // code... ...31 32 double area(double x1,double y1,double r1,double x2,double y2,double r2)33 {34 double d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);35 if(d>=(r1+r2)*(r1+r2)) return 0;36 if(d<=(r1-r2)*(r1-r2)) return r1
>T;51 for (int cnt=1;cnt<=T;cnt++)52 {53 double x1,y1,x2,y2,r1,r2;54 scanf("%lf%lf",&r1,&r2);55 scanf("%lf%lf",&x1,&y1);56 scanf("%lf%lf",&x2,&y2);57 double ans = area(x1,y1,r2,x2,y2,r2);58 ans -= 2*area(x1,y1,r1,x2,y2,r2);59 ans += area(x1,y1,r1,x2,y2,r1);60 printf("Case #%d: %.6f\n",cnt,ans);61 }62 }
View Code

 

 

 

 

 

 

转载于:https://www.cnblogs.com/haoabcd2010/p/6776400.html

你可能感兴趣的文章
Linux:命令执行控制&&与||
查看>>
麻球繁衍
查看>>
FreeRTOS栈溢出检查
查看>>
linux下,远程连接mysql
查看>>
浅谈js闭包(closure)
查看>>
【regex】POSIX标准正则表达式库
查看>>
C#集成FastReport.Net并将模板保存到数据库
查看>>
python装饰器(decorator)两种模式探讨集合
查看>>
高级 DO 语法
查看>>
Jexus下配置多个站点
查看>>
Xcode编辑器的技巧与诀窍
查看>>
String、StringBuffer与StringBuilder之间区别
查看>>
工作第十三周:身体掏空,精神饱满
查看>>
Linux 内核--任务0的运行(切换到用户模式)move_to_user_mode
查看>>
ios扩展机制objc_setAssociatedObject,objc_getAssociatedObject
查看>>
批量添加-fno-objc-arc
查看>>
二叉树的层序遍历
查看>>
os模块
查看>>
安装 matplotlib
查看>>
css伪类(:before和:after)
查看>>