hdu 5120 Intersection 两个圆的面积交
Intersection
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
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.
2 3
0 0
0 0
2 3
0 0
5 0
Case #2: 2.250778
题意:求两个圆环的面积交;
思路:圆环的面积交=大圆面积交-2*大小圆面积交+小圆面积交;
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fi first
#define se second
#define mkp make_pair
#define eps 1e-8
const double pi=acos(-);
const int N=2e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=; int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
Point() {}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x= tx*cos(B) - ty*sin(B);
y= tx*sin(B) + ty*cos(B);
}
}; double AREA(Point a, double r1, Point b, double r2)
{
double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
if (d >= r1+r2)
return ;
if (r1>r2)
{
double tmp = r1;
r1 = r2;
r2 = tmp;
}
if(r2 - r1 >= d)
return pi*r1*r1;
double ang1=acos((r1*r1+d*d-r2*r2)/(*r1*d));
double ang2=acos((r2*r2+d*d-r1*r1)/(*r2*d));
return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
double r1,r2;
Point a,b;
scanf("%lf%lf%lf%lf%lf%lf",&r1,&r2,&a.x,&a.y,&b.x,&b.y);
printf("Case #%d: %.6f\n",cas++,AREA(a,r2,b,r2)-AREA(a,r1,b,r2)-AREA(a,r2,b,r1)+AREA(a,r1,b,r1));
}
return ;
}
hdu 5120 Intersection 两个圆的面积交的更多相关文章
- 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 - 2892:area (圆与多边形交 求面积)
pro:飞行员去轰炸一个小岛,给出炸弹落地点的位置信息,以及轰炸半径:按顺时针或者逆时针给出小岛的边界点. 求被轰炸的小岛面积. sol:即是求圆和多边形的面积交. (只会套板子的我改头换面,先理解然 ...
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- HDU 5120 Intersection(几何模板题)
题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...
- poj3675 求多边形与圆的面积交
题意:给出多边形的顶点坐标.圆的圆心坐标和半径,求面积交 sol:又是模板题啦= = 注意poj的C++好像认不出hypot函数,要稍微改写一下. hypot(double x,double y):即 ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- hdu 5120 Intersection 圆环面积交
Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- hdu 5120 Intersection (圆环面积相交->圆面积相交)
Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...
随机推荐
- Javascript 面向对象编程1:封装
Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象.但是,他又不是一种真正的面向对象编程语言,因为它的语法中没有class(类). 那么,如果我们要把& ...
- Markdown使用笔记
下载地址:http://markdownpad.com/ 简明版 Markdown 语法说明(简体中文版) 完整版 Markdown 语法说明(简体中文版) 官方文档:http://www.markd ...
- ES6知识整理(6)--Symbol函数
(文章会同步到博客园,技术类文章还是该让搜索引擎察觉比较好) symbol是js的第7种数据类型: 7种分别是:undefined.null.boolean(布尔).string(字符串).numbe ...
- scrapy 去重 dont_filter=False
yield Request(...... dont_filter=False)
- Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
周五下午的时候升级了一个环境,跑了批处理sh升级脚本后,启动时报下列错误: INFO | jvm 1 | 2017/02/24 17:39:09 | java.io.IOException INFO ...
- 20145319 《网络渗透》免考—API拦截技术
20145319 <网络渗透>免考-API拦截技术 概述 本次实验在window环境下进行,主要通过编写hook代码和注入程序,将我们的hook代码通过dll文件的形式注入到目标中,拦截其 ...
- nodejs 开发,手把手开始第一个服务器程序(原生)
此文章为原生 nodejs ,仅做学习使用 想学习 express 和 koa2 的小伙伴请绕路 此文章适合有HTML 和css .js 基础的小伙伴看哦 如果能帮到你,荣幸之至 文章纯手打,如有纰 ...
- ATL、MFC、WTL CString 的今生前世(转载)
转载:https://www.cnblogs.com/tekkaman/archive/2011/04/20/2022650.html 上文分析了ATL.MFC CString的设计和实现,我们不禁会 ...
- Java:The hierarchy of the type is inconsistent错误
错误 The type com.jiuqi.dna.ui.language.INLStringGroup cannot be resolved. It is indirectly referenced ...
- 【做题】codechefCOUNTARI——分块FFT
记本题数组长度为\(n\),权值大小为\(m\). 首先,暴力显然是\(O(n^2)\)的. 先瞄一眼tag,然后发现这是FFT. 显然,问题的关键在于要满足i,j,k之间的位置关系.于是考虑分治FF ...