poj 2546 Circular Area(两个圆相交的面积)
2016-07-27 15:08
567 查看
Circular Area
Description
Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.
Input
In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.
Output
The output file must contain single real number - the area.
Sample Input
Sample Output
Source
Northeastern Europe 2000, Far-Eastern Subregion
题意:给第一个圆的圆心坐标和半径,再给第二个圆的圆心坐标和半径,求两个圆的相交面积。
几何题,刚开始接触,照着别人代码理解完成自己的代码。
![](https://oscdn.geek-share.com/Uploads/Images/Content/202009/04/49a5e9473f0229f93987255ac18b75c1.png)
两种情况一次分析就好,情况相同~
附上代码:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5716 | Accepted: 2239 |
Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.
Input
In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.
Output
The output file must contain single real number - the area.
Sample Input
20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
608.366
Source
Northeastern Europe 2000, Far-Eastern Subregion
题意:给第一个圆的圆心坐标和半径,再给第二个圆的圆心坐标和半径,求两个圆的相交面积。
几何题,刚开始接触,照着别人代码理解完成自己的代码。
![](https://oscdn.geek-share.com/Uploads/Images/Content/202009/04/49a5e9473f0229f93987255ac18b75c1.png)
两种情况一次分析就好,情况相同~
附上代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define ll long long #define M 100005 using namespace std; const double pi = acos(-1.0); struct Round { double x,y; double r; } rr[2]; double dis(Round a, Round b) { return sqrt((a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y)); ///求两点之间的距离 } double solve(Round a, Round b) { double d = dis(a, b); if(d >= a.r + b.r) ///相离的情况 return 0; else if(d <= fabs(a.r - b.r)) ///内含的情况 { double r = a.r < b.r?a.r : b.r; return pi*r*r; } double ang1 = acos((a.r * a.r + d * d - b.r * b.r) / 2.0 / a.r / d); ///公式: cos(A)=(b^2+c^2-a^2)/2bc acos(cos(A))求出角A的弧度 double ang2 = acos((b.r * b.r + d * d - a.r * a.r) / 2.0 / b.r / d); double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1); ///扇形面积s=弧度*r^2/2 三角形面积=a*b*sin(A)/2 return ret; } int main() { while(~scanf("%lf%lf%lf%lf%lf%lf",&rr[0].x,&rr[0].y,&rr[0].r,&rr[1].x,&rr[1].y,&rr[1].r)) { printf("%.3lf\n",solve(rr[0], rr[1])); } return 0; }
相关文章推荐
- 【糖衣炮弹】通过注释巧妙实现#if{}#else{}#endif功 4000 能
- fedora24安装xmind7
- 使用PrintWriter(System.out)没有数据输出到控制台上的问题
- IIS7.5优化,支持同时10万个请求
- Inno Setup入门(十二)——Pascal脚本(1)
- Minimum Path Sum
- WCF配置详解
- python学习笔记2(对象)
- RX操作符之Observable的创建方式二(defer、range、interval、timer、Empty、Never、Throw)
- Ubuntu 14.04 文件服务器--samba的安装和配置
- AngularJS中如何使用trigger报错$digest already in progress
- Glide的使用(加载图片,动态图,缩略图,视频解码等)
- freeSSHd开启ssh出错
- 如何在生产环境删除百万级以上的数据
- String类中类型的区分
- 手机端(android与ios)黑客安全检测工具锦集
- Android应用层View绘制流程与源码分析
- Java:按值传递还是按引用传递详细解说
- MySQL 学习总结-聚合函数总结
- HDU 1531 King (差分约束)