HDOJ 5120 Intersection(求两圆相交面积)
来源:互联网 发布:六级词汇书推荐知乎 编辑:程序博客网 时间:2024/04/29 05:35
求两个圆环相交面积,直接容斥即可。
圆环面积 = 两个大圆面积交 - 大圆和小圆交 * 2 + 两个小圆交。
#include <iostream>#include <stdlib.h>#include <stdio.h>#include <math.h>using namespace std;#define eps 1e-8#define pi acos(-1.0)int sig(double x){ return (x > eps) - (x < -eps);}typedef struct Point{ double x, y; Point() {} Point(double _x, double _y): x(_x), y(_y) {} Point operator -(const Point &argu) const { return Point(x - argu.x, y - argu.y); } bool operator <(const Point &argu) const { if(sig(x - argu.x) == 0) return y < argu.y; return x < argu.x; } double dis(const Point &argu) const { return sqrt((x - argu.x) * (x - argu.x) + (y - argu.y) * (y - argu.y)); }}pp;typedef struct Circle{ Point o; double r; Circle() {} Circle(Point _o, double _r): o(_o), r(_r) {} bool operator <(const Circle &argu) const { if(sig(r - argu.r) == 0) return o < argu.o; else return r < argu.r; } ///参数圆半径更小些 double Intersection_Area(const Circle &argu) const { double d = ((*this).o).dis(argu.o); if(sig(d - r - argu.r) >= 0) return 0; if(sig(r - argu.r - d) >= 0 || sig(d) == 0) return pi * argu.r * argu.r; double ang1 = acos((argu.r * argu.r + d * d - r * r) / (2 * argu.r * d)); double ang2 = acos((r * r + d * d - argu.r * argu.r) / (2 * r * d)); return ang1 * argu.r * argu.r + ang2 * r * r - argu.r * d * sin(ang1); }}cc;cc c1[2], c2[2];double calc(){ scanf("%lf %lf", &c1[0].r, &c1[1].r); c2[0].r = c1[0].r, c2[1].r = c1[1].r; scanf("%lf%lf", &c1[0].o.x, &c1[0].o.y); c1[1].o.x = c1[0].o.x, c1[1].o.y = c1[0].o.y; scanf("%lf%lf", &c2[0].o.x, &c2[0].o.y); c2[1].o.x = c2[0].o.x, c2[1].o.y = c2[0].o.y; return c1[1].Intersection_Area(c2[1]) - c1[1].Intersection_Area(c2[0]) - c2[1].Intersection_Area(c1[0]) + c1[0].Intersection_Area(c2[0]);}int main(){// freopen("5120.in", "r", stdin); int t; scanf("%d", &t); for(int cas = 1; cas <= t; cas++) { printf("Case #%d: %.6lf\n", cas, calc()); }return 0;}
0 0
- HDOJ 5120 Intersection(求两圆相交面积)
- HDOJ Intersection 5120【环相交面积】
- hdoj 5120 Intersection 【计算圆环相交面积】
- HDU 5120 Intersection 求两圆相交面积模板
- hdoj Intersection 5120 (数学计算几何) 求两个相交圆的面积
- hdu 5120 Intersection(两圆相交面积)(模板)
- hdu 5120 Intersection(求相交圆的面积)
- hdu 5120 Intersection(求相交圆的面积)
- hdoj.5120 Intersection【计算几何-两圆相交面积】 2015/08/01
- HDU-5120-Intersection【几何-相交圆面积】
- hdu 5120 Intersection(求相交环面积)
- Hdu 5120 Intersection【计算圆环相交面积】
- HDU 5120 Intersection 圆相交面积
- hdu 5120 Intersection (圆相交面积模板)
- HUD Intersection 5120(两圆环相交求相交面积)
- HDOJ 5120 Intersection 两圆面积交
- 几何 两元相交的面积计算问题 HDU 5120 Intersection(几何模板)
- hdu 5120 Intersection (容斥原理+圆的相交面积模板)
- Quartus rom 初始化文件hex modelsim仿真问题
- Retinex系列之McCann99 Retinex
- 寻找最小的k个数
- I2S音频总线学习(二)I2S总线协议
- oracle date数据的条件查询
- HDOJ 5120 Intersection(求两圆相交面积)
- JPA实体标识的自动生成
- jQuery中$.ajax解析xml、json格式数据
- Java反射工具类
- 解析
- jsp+java用pageoffice在线编辑office文档
- iPhone 中使用NSLocalizedString实现国际化
- 【BZOJ2631】tree Link-Cut-Tree
- 【LeetCode】Min Stack 解题报告