POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
题目链接:
problemId=597" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597
Description
Input
Output
Sample Input
- 20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
- 608.366
Source
题意:
求两圆相交的面积!
直接上模板
代码例如以下:
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <iostream>
- #include <algorithm>
- //#include <complex>
- //#include <iomanip>
- using namespace std;
- const double eps = 1e-8;
- const double PI = acos(-1.0);
- int sgn(double x)
- {
- if(fabs(x) < eps) return 0;
- if(x < 0) return - 1;
- else return 1;
- }
- 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 dist( Point a, Point b)
- {
- return sqrt((a-b)*(a- b));
- }
- //两个圆的公共部分面积
- double Area_of_overlap(Point c1, double r1, Point c2, double r2)
- {
- double d = dist(c1,c2);
- if(r1 + r2 < d + eps) return 0;
- if(d < fabs(r1 - r2) + eps)
- {
- double r = min(r1,r2);
- return PI*r*r;
- }
- double x = (d*d + r1*r1 - r2*r2)/(2*d);
- double t1 = acos(x / r1);
- double t2 = acos((d - x)/r2);
- return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
- }
- int main()
- {
- double x1, y1, r1, x2, y2, r2;
- while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))
- {
- Point c1, c2;
- c1.x = x1;
- c1.y = y1;
- c2.x = x2;
- c2.y = y2;
- double ans = Area_of_overlap(c1,r1,c2,r2);
- printf("%.3lf\n",ans);
- //cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;
- }
- return 0;
- }
POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)的更多相关文章
- 求两圆相交部分面积(C++)
已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- poj2546Circular Area(两圆相交面积)
链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- 两圆相交求面积 hdu5120
转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...
- [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点
POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...
- ZOJ 1280 Interesting Lines | 求两直线交点
原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
随机推荐
- yum安装失败:ublic key for **.rpm is not installed
yum install mysql-server --nogpgcheck package_need_to_install
- Apache+Tomcat+mod_jk实现负载均衡
最近公司提出了负载均衡的新需求,以减轻网站的高峰期的服务器负担.趁空闲时间我就准备了一下这方面的知识,都说有备无患嘛.网上相关资料很多,但是太散.我希望可以通过这篇随笔,系统的总结. 一.Tomcat ...
- [Android]使用 Eclipse 给 APK 签名时遇到的两个问题及解决办法
问题 今天用 APK 反编译工具看了一下自己项目生成的 APK 文件,发现代码并没有混淆,于是设置了用 ProGuard 混淆代码,可是混淆是必须在非 Debug 模式才会生效的,即使你是以 Rele ...
- Angularjs里面跨作用域的实战!
好久没有来写博客了,最近一直在用Google的AngularJS,后面我自己简称AngularJS就叫AJ吧! 学习AngularJS一路也是深坑颇多啊--!就不多说了,不过还是建议大家有时间去学下下 ...
- docker stack 部署nginx
=============================================== 2018/7/29_第1次修改 ccb_warlock == ...
- ajax发送多个跨域请求回调不混乱
var count = 0; var codes = ""; function refreshCache(urls){ try { var url = urls.split(&qu ...
- js防止sql注入的参数过滤
js防止sql注入的参数过滤 <script language="javascript"> <!-- var url = location.search; var ...
- php生成随机数
生成1-10之间的随机数,不重复. 方法一:用shuffle函数. <?php $arr=range(1,10); shuffle($arr); foreach($arr as $values) ...
- 【LOJ】#2110. 「JLOI2015」管道连接
题解 我们先跑一个斯坦纳树出来 斯坦纳树是什么,是一个包含点集里的点联通所需要的最小的价值,显然他们联通的方式必然是一棵树 我们可以设一个状态为\(dis[i][S]\)表示以第i个点为根,点集为\( ...
- redis 相关知识点
(1)什么是redis? Redis 是一个基于内存的高性能key-value数据库. (有空再补充,有理解错误或不足欢迎指正) (2)Reids的特点 Redis本质上是一个Key-Value类型的 ...