lightoj 1118 Incredible Molecules 圆面积求交,模板

看了kuangbin神的版子,自己的都不敢往上贴了。。。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <stack>

using namespace std;
const double Pi=acos(-1.0);
const double eps=1e-10;
double add(double a,double b) //有误差的浮点加法
{
if(abs(a + b) < eps * (abs(a) + abs(b))) return 0;
return a + b;
}
struct Point
{
    double x,y;
    Point(double tx = 0,double ty = 0) : x(tx),y(ty) {}
    Point operator + (Point p)
    {
        return Point(add(x,p.x),add(y,p.y));
    }
    Point operator - (Point p)
    {
        return Point(add(x,-p.x),add(y,-p.y));
    }
    Point operator * (double d)
    {
        return Point(x * d,y * d);
    }
    Point operator / (double d)
    {
        return Point(x / d,y / d);
    }
    Point Move(double a,double d)//从x正方向开始,逆时针
    {
        return Point(x + d * cos(a),y + d * sin(a));
    }
    void Read()
    {
        scanf("%lf%lf",&x,&y);
    }
};

struct Circle
{
    Point o;
    double r;
    Circle(double tx = 0,double ty = 0,double tr = 0) : o(tx,ty),r(tr) {}
    void Read()
    {
        o.Read();
        scanf("%lf",&r);
    }
    void Out()
    {
        printf("%.8f %.8f %.8f\n",o.x,o.y,r);
    }
    double Area()
    {
        return r*r*Pi;
    }
};
double x_mult(Point sp, Point ep, Point op)//叉积
{
    return (sp.x-op.x)*(ep.y-op.y)-(sp.y-op.y)*(ep.x-op.x);
}
double cross(Point a,Point b,Point c)//点积
{
    return (a.x-c.x)*(b.x-c.x)+(a.y-c.y)*(b.y-c.y);
}
double dist(Point a,Point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double solve(Circle c1,Circle c2)
{
    double d=dist(c1.o,c2.o);
    if (c1.r+c2.r<d+eps)return 0;
    if (d<fabs(c1.r-c2.r)+eps)
    {
        double r=min(c1.r,c2.r);
        return Pi*r*r;
    }
    double x=(d*d+c1.r*c1.r-c2.r*c2.r)/(2*d);
    double t1=acos(x/c1.r);
    double t2=acos((d-x)/c2.r);
    return c1.r*c1.r*t1+c2.r*c2.r*t2-d*c1.r*sin(t1);
}
int main()
{
    int T,ncas=1;
    scanf ("%d",&T);
    while (T--)
    {
        Circle c1,c2;
        c1.Read();
        c2.Read();
        printf ("Case %d: %.10f\n",ncas++,solve(c1,c2));
    }
    return 0;
}

转载于:https://www.cnblogs.com/nj-czy/p/5573557.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值