Intersection

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

Total Submission(s): 602 Accepted Submission(s): 247

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

题意

给你两个完全一样的圆环,圆环,圆环

因为很重要,所以要说三遍

然后求他们相交的面积

题解

那就直接套模板吧!!!

套板大作战,相交面积=大圆交-2*大小交+小交

代码

  1. #define inf 0x7fffffff
  2. #define exp 1e-10
  3. #define PI 3.141592654
  4. using namespace std;
  5. typedef long long ll;
  6. struct Point
  7. {
  8. double x,y;
  9. Point (double x=0,double y=0):x(x),y(y){}
  10. };
  11. double dist(Point a,Point b)
  12. {
  13. double x=(a.x-b.x)*(a.x-b.x);
  14. double y=(a.y-b.y)*(a.y-b.y);
  15. return sqrt(x+y);
  16. }
  17. double Area_of_overlap(Point c1,double r1,Point c2,double r2)
  18. {
  19. double d=dist(c1,c2);
  20. if (r1+r2<d+exp) return 0;
  21. if (d<fabs(r1-r2)+exp)
  22. {
  23. double r=min(r1,r2);
  24. return PI*r*r;
  25. }
  26. double x=(d*d+r1*r1-r2*r2)/(2*d);
  27. double t1=acos(x/r1);
  28. double t2=acos((d-x)/r2);
  29. return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
  30. }
  31. int main()
  32. {
  33. int t,ncase=1;
  34. double r,R;
  35. Point a,b;
  36. scanf("%d",&t);
  37. while (t--)
  38. {
  39. scanf("%lf%lf",&r,&R);
  40. scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
  41. double bb_area=Area_of_overlap(a,R,b,R);
  42. double bs_area=Area_of_overlap(a,R,b,r);
  43. double ss_area=Area_of_overlap(a,r,b,r);
  44. printf("Case #%d: %.6lf\n",ncase++,bb_area-2.0*bs_area+ss_area);
  45. }
  46. return 0;
  47. }

hdoj 5120 Intersection 圆环面积求交的更多相关文章

  1. hdu 5120 Intersection 圆环面积交

    Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  2. hdu 5120 Intersection (圆环面积相交->圆面积相交)

    Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...

  3. POJ 1151 Atlantis 矩形面积求交/线段树扫描线

    Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...

  4. HDU 5120 Intersection (圆的面积交)

    题意:给定两个圆环,求两个圆环的面积交. 析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交. 代码如下: #pragma commen ...

  5. 三角剖分求多边形面积的交 HDU3060

    //三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...

  6. hdu1255 覆盖的面积 线段树+里离散化求矩形面积的交

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 求矩形面积的交的线段树题目,刚做了求并的题目,再做这个刚觉良好啊,只要再加一个表示覆盖次数大于1 ...

  7. 光线求交-面、三角形、球 (Ray intersection)

    光线求交 光线定义:position \(a(t)\) = \(o\) + \(t\vec{d}\); 球定义: center p, radius r; 平面定义:normal \(\vec{n}\) ...

  8. hdu 5120 Intersection

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...

  9. [NetTopologySuite](2)任意多边形求交

    任意多边形求交: private void btnPolygon_Click(object sender, EventArgs e) { , , , , , , , , , , , , , }; , ...

随机推荐

  1. Python string interning原理

    原文链接:The internals of Python string interning 由于本人能力有限,如有翻译出错的,望指明. 这篇文章是讲Python string interning是如何 ...

  2. OSGiBundle出现 Could not find bundle: org.eclipse.equinox.console的解决方案

    按照网上教程创建OSGI HelloWorld实例配置run configuration时出现Could not find bundle: org.eclipse.equinox.console 和C ...

  3. R语言以及RStdio的安装

    R语言: 首先从官网上下载R安装包, 提供了Linux, (Mac) OS X, Windows的安装包相关下载链接. RStdio: RStdio(官网)是R言语非常实用的IDE, 是一个免费的软件 ...

  4. TDictionary 与 TObjectDictionary

    TDictionary 与 TObjectDictionary 的区别是 : TObjectDictionary 可以做到 free的时候 里面的对象 一并free,从而不会出现内存 泄露. 用途: ...

  5. NYOJ 石子合并(一)(区间DP)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=737 题目大意: 有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆 ...

  6. AT994 【11の倍数】

    超短AC代码压行小技巧 #include<iostream> using namespace std; string s; ]; int main() { cin>>s; in ...

  7. COLLATE CHINESE_PRC_CI_AS_WS 的含义

    排序规则:COLLATE CHINESE_PRC_CI_AS_WS 的含义 在创建数据表时,常会用到这个. 含义当中,CHINESE_prc_ 是代表中国大陆.如果是台湾,则如:Chinese_TAI ...

  8. Git简明教程二、开始进行版本管理

    上一篇介绍了Git中的一些基本概念.本篇来实际看一看如何通过几个常用命令来快速上手Git,完成版本管理的日常操作(核心操作). 0. 准备工作 安装Git后,请先在你的电脑上新建或选择一个目录作为测试 ...

  9. JAVA 解析TXT文本

    package file; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...

  10. day2编写购物商城

    作业:购物商城 商品展示,价格 买,加入购物车 付款,钱不够 流程图如下: 代码共有4个文件,如下: 用户文件: alex geng zhang lou zeng 商品文件: 小米3 比亚迪宋 格力变 ...