POJ 2546 Circular Area(两圆相交面积模版题)
来源:互联网 发布:linux打开exe文件类型 编辑:程序博客网 时间:2024/05/16 19:00
Circular Area
Time Limit: 1000MS
Memory Limit: 65536KTotal Submissions: 5901
Accepted: 2298
以下是AC代码
Memory Limit: 65536KTotal Submissions: 5901
Accepted: 2298
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
题目大意,给你两个圆的坐标和半径,求两圆相交的面积有多大,输出保留三位小数。
以下是求两圆相交的模版
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);}
以下是AC代码
#include<cstdio>#include<iostream>#include<cmath>using namespace std;const double eps=1e-8; const double PI = acos(-1.0);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.x + y*b.y; }}; 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(){Point c1,c2;double r1,r2;scanf("%lf%lf%lf%lf%lf%lf",&c1.x,&c1.y,&r1,&c2.x,&c2.y,&r2);double ans= Area_of_overlap(c1 , r1 , c2 , r2 );printf("%.3f\n",ans);return 0;}
阅读全文
1 0
- POJ 2546 Circular Area(两圆相交面积模版题)
- poj 2546 Circular Area (两圆相交面积)
- POJ 2546 Circular Area 两圆相交面积
- POJ 2546 Circular Area(两个圆相交面积)
- POJ 2546 Circular Area(计算几何 两圆相交面积)
- Circular Area 两圆相交面积(模板)
- TOJ 1754.Circular Area(两圆相交求面积)
- poj2546—Circular Area(两圆相交面积)
- Poj.2546 Circular Area【两圆相交面积】 2015/09/23
- POJ 2546 Circular Area【计算几何,计算两圆相交面积】
- poj 2546 Circular Area 两圆面积交
- POJ 2546 || Circular Area(两圆面积交
- TOJ 1754 Circular Area 两圆相交的面积
- POJ 2546 Circular Area [相交园面积]【计算几何】
- POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
- POJ 2546 & ZOJ 1597 Circular Area 两圆的面积交
- ZOJ.1597 Circular Area【两圆相交面积】 2015/09/23
- zoj 1597 Circular Area(求两圆相交的面积)
- spark1.x-spark-sql性能优化
- ConcurrentHashMap原理分析
- QML自定义控件Button
- urlib.unquote函数
- Cannot find name 'Article'的解决方案
- POJ 2546 Circular Area(两圆相交面积模版题)
- Asp.Net之Session简介及使用
- 数据同步
- Android进阶Support Annotation Library 使用详解
- RedisClusterManagerUtil 工具类
- php原理简述
- springboot学习10之jersey+mybatis+通用mapper+分页PageHelper
- Python高阶函数-map和reduce
- 前端即时搜索的触发(input propertychange)