计算几何(容斥原理,圆交):HDU 5120 Intersection

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
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
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 <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int T,cas,r,R,px,py,qx,qy;
const double Pi=acos(-1.0);
double sqr(double x){return x*x;}
double Q(double r1,double r2){
double d=sqrt(sqr(px-qx)+sqr(py-qy));
if(r1+r2<=d)return ;
if(r1-r2>=d)return Pi*sqr(r2);
double a1=acos((sqr(r1)+sqr(d)-sqr(r2))/(*r1*d));
double a2=acos((sqr(r2)+sqr(d)-sqr(r1))/(*r2*d));
double s1=sqr(r1)*a1;
double s2=sqr(r2)*a2;
return s1+s2-r1*sin(a1)*d;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&r,&R);
scanf("%d%d%d%d",&px,&py,&qx,&qy);
printf("Case #%d: %.6lf\n",++cas,Q(R,R)-*Q(R,r)+Q(r,r));
}
return ;
}
计算几何(容斥原理,圆交):HDU 5120 Intersection的更多相关文章
- hdu 5120 Intersection 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- HDU 5120 Intersection (圆的面积交)
题意:给定两个圆环,求两个圆环的面积交. 析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交. 代码如下: #pragma commen ...
- hdu 5120 Intersection 圆环面积交
Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- hdu 5120 Intersection
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...
- hdu 5120 Intersection (圆环面积相交->圆面积相交)
Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...
- HDU 5120 Intersection(几何模板题)
题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...
- Intersection(HDU5120 + 圆交面积)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5120 题目: 题意: 求两个圆环相交的面积. 思路: 两个大圆面积交-2×大圆与小圆面积交+两小圆面 ...
- HDU 3467 Song of the Siren(圆交)
Problem Description In the unimaginable popular DotA game, a hero Naga Siren, also known as Slithice ...
随机推荐
- ARC和MRC实现单例模式
代码如下,可直接拷贝到头文件中 #define singleton_h(name) +(instancetype)shared##name # if __has_feature(objc_arc) / ...
- Source Insight及常用插件
Source Insight及常用插件 1.Source Insight 2.插件 <1>.使用快捷键注释,单行注释,多行注释,#if 0注释 <2>.跳转到当前文件所在的文件 ...
- ASP.NET中Json的处理
要使用.NET自带的JSON处理工具需要引用下面的命名空间: using System.Web.Script.Serialization; 1.编码 myConfig mc = new myConfi ...
- ASP.NET错误页
当页面发生错误的时候,ASP.Net会将错误信息展示出来,这样一来不好看,二来会泄露网站的内部实现信息,给网站带来安全隐患,因此需要定制错误页,发生错误时显示开发人员定制的页面404页面放点广告也是好 ...
- 菜鸟的MySQL学习笔记(四)
MySQL中的运算符和函数: 1.字符函数: 2.数值运算符与函数: 3.比较运算符与函数: 4.日期时间函数: 5.信息函数: 6.聚合函数: 7.加密函数等: 6-1.字符函数: CONCAT ...
- Spring Cloud Eureka Server例子程序
Spring-Cloud-Eureka-Server 及Client 例子程序 参考源代码:https://github.com/spring-cloud-samples/eureka 可以启动成功, ...
- gentoo下的wpa_supplicant无线网配置
在linux使用wpa_supplicant获得无线网的最痛苦的是莫过于去配置wpa_supplicant.conf文件了(当然对于linux老手这不算什么), 但是可以用一种简便的方法直接输入命令行 ...
- PHP程序实现利用rand(1,100)函数产生10个1~100之间的随机数
//echo rand(1,100);$max=0;$min=100;for($i=0;$i<=9;$i++){ $rand[$i]=rand(1,100); if($rand[$i]>$ ...
- Android使用adb工具及root权限完成手机抓包
1.环境准备/注意: 手机要求已经root. 首先需要配置JDK环境变量,这里主要讲解抓包,JDK环境变量配置跳过. 将包内附带的adb.zip解压到C盘根目录. 整个操作过程都需要用手机用数据线连 ...
- Django中国|Django中文社区——python、django爱好者交流社区
Django中国致力于成为Python和Django框架等技术的中文开发者学习交流平台. 内容涵盖python教程.python基础.Django教程.python入门.web.py教程.linux教 ...