POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
来源:互联网 发布:数据分析模型作用 编辑:程序博客网 时间:2024/04/30 00:09
题目链接:
POJ:http://poj.org/problem?id=2546
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597
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
20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
608.366
Source
Northeastern Europe 2000, Far-Eastern Subregion
题意:
求两圆相交的面积!
直接上模板
代码如下:
#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;}
2 0
- POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
- zoj 1597 Circular Area(求两圆相交的面积)
- zoj 1597 Circular Area (求两园相交面积)
- POJ 2546 Circular Area(两个圆相交面积)
- poj 2546 Circular Area (两圆相交面积)
- POJ 2546 & ZOJ 1597 Circular Area 两圆的面积交
- Circular Area 两圆相交面积(模板)
- POJ 2546 Circular Area [相交园面积]【计算几何】
- POJ 2546 Circular Area 两圆相交面积
- POJ 2546 Circular Area(计算几何 两圆相交面积)
- POJ 2546 Circular Area(两圆相交面积模版题)
- zoj 1597 || poj 2546 Circular Area(数学题)
- ZOJ.1597 Circular Area【两圆相交面积】 2015/09/23
- ZOJ 1597 Circular Area(POJ 2546)(两个圆的位置关系)
- Poj.2546 Circular Area【两圆相交面积】 2015/09/23
- POJ 2546 Circular Area【计算几何,计算两圆相交面积】
- TOJ 1754 Circular Area 两圆相交的面积
- TOJ 1754.Circular Area(两圆相交求面积)
- 刚刚在寻找微博
- Data Type of String
- 配置JBOSS多实例
- HDU 4521 小明系列问题——小明序列 (线段树维护DP)
- linux虚拟机新增额外硬盘的方法
- POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
- 解决ajax时出现No Transport
- 关于对象
- [LeetCode]Merge Sorted Array
- Beginning Python From Novice to Professional (6) - 函数使用
- oracle用户权限视图小结
- java 多维数组
- xna 摄像机的旋转!
- 设计模式C++实现一 工厂模式