H电-Problem Archive-5120-Intersection
来源:互联网 发布:出国英文翻译软件 编辑:程序博客网 时间:2024/05/22 07:46
Intersection
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 177 Accepted Submission(s): 76
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
Source
2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)
S:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;double w = 1e-8;double pi = acos(-1.0);struct node{ double x, y;}p, q;double f(node a,double r,node b,double R){ double d = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); if(d >= r + R + w) return 0; if(fabs(R - r) + w >= d){ int rr = min(r, R); return pi * rr * rr; } double x = (r * r + d * d - R * R) / (2 * d); double g1 = acos(x / r); double g2 = acos((d - x) / R); return r * r * g1 + R * R * g2 - d * r * sin(g1);}int main(){ int T, k = 1; double ans; scanf("%d", &T); while(T--){ double x1, x2, y1, y2, r1, r2; scanf("%lf%lf%lf%lf%lf%lf", &r1, &r2, &x1, &y1, &x2, &y2); q.x = x1, q.y = y1; p.x = x2, p.y = y2; /* if(x1 == x2 && y1 == y2){ printf("Case #%d: %.6lf\n", k++, ans); continue; } */ double ans = f(q, r2, p, r2) - f(q, r1, p, r2) - f(q, r2, p, r1) + f(q, r1, p, r1); printf("Case #%d: %.6lf\n", k++, ans); } return 0;}
0 0
- H电-Problem Archive-5120-Intersection
- H电-Problem Archive-5105-Math Problem
- H电-Problem Archive-1009-FatMouse' Trade
- H电-Problem Archive-2154-跳舞毯
- H电-Problem Archive-2089-不要62
- H电-Problem Archive-1879-继续畅通工程
- H电-Problem Archive-2141-Can you find it?
- H电-Problem Archive-5110-Alexandra and COS
- H电-Problem Archive-5123-who is the best?
- H电-Problem Archive-4520-小Q系列故事——最佳裁判
- H电-Prolem Archive-1075-What Are You Talking About
- 杭电OJ 第一周 Problem H:小虫子爬爬爬~
- acm/icpc live archive 2481, world final 2002 problem h. silly sort
- 杭电5120 Intersection(圆面积并)
- Problem H
- Problem H
- Problem H
- Problem H
- 没想到这几个不同的drawable文件夹还真不一样
- Android开源项目分类汇总
- 小马哥------高仿机 杂牌机常识与刷机救砖心得与技巧
- 无锁队列的实现
- UVa 127 - "Accordian" Patience(模拟)
- H电-Problem Archive-5120-Intersection
- 短URL简介
- DOS命令大全--详解
- Template Method模式
- . 说反话-加强版 (20)(12fen 部分对)
- C#中的序列化
- swift实战-豆瓣电台
- 人品计算器
- zoj3838浙大月赛 大模拟