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.
Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.
#include <bits/stdc++.h> using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-;
int dblcmp (double k)
{
if (fabs(k)<eps) return ;
return k>?:-;
}
struct Point
{
double x,y;
};
double dis (Point a,Point b)
{
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double area_of_overlap (Point c1,double r1,Point c2,double r2)//圆相交模板
{
double d = dis(c1,c2);
if (r1+r2<d+eps) return ;
if (d<fabs(r1-r2)+eps){
double r = min(r1,r2);
return PI*r*r;
}
double x = (d*d+r1*r1-r2*r2)/(*d);
double t1 = acos(x/r1);
double t2 = acos((d-x)/r2);
return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
}
int t;
int casee = ;
int main()
{
//freopen("de.txt","r",stdin);
scanf("%d",&t);
while (t--){
Point p1,p2;
double r1,r2;
scanf("%lf%lf",&r1,&r2);
scanf("%lf%lf",&p1.x,&p1.y);
scanf("%lf%lf",&p2.x,&p2.y);
if (dblcmp(r1-r2)>) swap(r1,r2);
double ans = area_of_overlap (p1,r2,p2,r2) -area_of_overlap (p1,r2,p2,r1)
-(area_of_overlap (p1,r1,p2,r2) - area_of_overlap(p1,r1,p2,r1) );
/*double ans = area (p1,r2,p2,r2) -area (p1,r2,p2,r1)
-(area(p1,r1,p2,r2) - area(p1,r1,p2,r1) );*/
printf("Case #%d: %.6f\n",++casee,ans);
}
return ;
}
hdu 5120 Intersection (圆环面积相交->圆面积相交)的更多相关文章
- hdu 5120 Intersection 圆环面积交
Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- hdoj 5120 Intersection 圆环面积求交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Tota ...
- hdu 5120(2014北京—求圆相交)
题意:求环的相交面积 思路: 通过画图可知,面积= 大圆相交面积 - 大小圆相交面积*2 + 小小圆相交面积 再通过圆相交模板计算即可 #include <iostream> #incl ...
- HDU 5120 Intersection (圆的面积交)
题意:给定两个圆环,求两个圆环的面积交. 析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交. 代码如下: #pragma commen ...
- 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 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- HDU 5120 Intersection(几何模板题)
题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
随机推荐
- 从零开始创建 symfony-cmf
前提: 官方 https://symfony.com/doc/master/cmf/quick_tour/the_big_picture.html#setting-up-the-database 由于 ...
- Validform验证插件
http://validform.club/index.html
- 02 - Jmeter4.x正则表达式以及跨线程使用变量
话不多说 直接开撸 上图可以看出,有两个请求,其中第二个请求返回了登录超时,结合第一个登录接口来看,这个是需要header请求内容的也就是 token:当然设置一个token又怎么可能难得倒我们,无非 ...
- 转 router-view 的理解
主要是构建 SPA (单页应用) 时,方便渲染你指定路由对应的组件.你可以 router-view 当做是一个容器,它渲染的组件是你使用 vue-router 指定的.比如: 视图层: <div ...
- Server Tomcat v8.5 Server at localhost failed to start.
问题描述:新建了一个项目,建立servlet文件然后改了下@WebServlet("floorButtonServlet")映射的路径,重启debug之后服务器启动失败. 在网上查 ...
- BUUCTF--新年快乐
测试文件:https://buuoj.cn/files/bbf9f68a97fd551edec384914d4f3fbe/93c43c5c-3d4d-4d17-a9a1-4ffb65ebb2fb.zi ...
- 一些常见的js校验
今天有时间来总结一下那些常用的js校验: vernull = function(value){//非空校验 if(value.trim(value).length == 0){ return fals ...
- 基于TensorFlow Object Detection API进行迁移学习训练自己的人脸检测模型(二)
前言 已完成数据预处理工作,具体参照: 基于TensorFlow Object Detection API进行迁移学习训练自己的人脸检测模型(一) 设置配置文件 新建目录face_faster_rcn ...
- RabbitMQ数据同步一致性解决方案
1.概述 我们知道在使用RabbitMQ时,生产者将消息发布出去之后,消息是否顺利到达broker代理服务器呢?默认情况下发布操作没有任何信息返回给生产者,也就是生产者是不知道消息有没有顺利到达bro ...
- ssh-keygen - 认证密钥的产生, 管理和转换
总览 (SYNOPSIS) ssh-keygen -words [-q ] [-b bits ] -t type [-N new_passphrase ] [-C comment ] [-f outp ...